xcode 在 iPhone 的 UILabel 中添加图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8709294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
adding image in UILabel in iPhone
提问by Gurumoorthy Arumugam
i have UIlabel with image.my text are won't come into top of the image i want to show my text in top of the image.
我有带有图像的 UIlabel。我的文本不会出现在图像的顶部,我想在图像的顶部显示我的文本。
image1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"salarytax.png"]];
this is my code to adding image to label. this image is a output of that code. how can i show the text in top of the image
这是我将图像添加到标签的代码。该图像是该代码的输出。如何在图像顶部显示文本
回答by Suresh Varma
try adding the UILabel
on the image
尝试UILabel
在图像上添加
[myimageview addSubView: myLabel];
[myImageView bringSubviewToFront: myLabel];
If you have just taken the UILabel
and trying to set its background as an image then dont think it would create a problem.
如果您刚刚拍摄UILabel
并尝试将其背景设置为图像,那么不要认为这会造成问题。
If you are able to view the text on the label but you want the text to be vertically on top then you can set its contentVerticalAlignment
property to top.
如果您能够查看标签上的文本,但希望文本垂直位于顶部,则可以将其contentVerticalAlignment
属性设置为顶部。
Hope this helps..
希望这可以帮助..
回答by Khalid Usman
UILabel *imageLabel;
[imageLabel setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"logo.png"]]];
[imageLabel setText:@"Khalid Usman"];
[imageLabel setTextColor:[UIColor blackColor]];
Note: I have checked it for conformation then i post. It's working.
注意:我已经检查了它的构造然后我发布了。它正在工作。