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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 22:52:52  来源:igfitidea点击:

adding image in UILabel in iPhone

iphoneobjective-cxcode

提问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 enter image description here

这是我将图像添加到标签的代码。该图像是该代码的输出。如何在图像顶部显示文本在此处输入图片说明

回答by Suresh Varma

try adding the UILabelon the image

尝试UILabel在图像上添加

[myimageview addSubView: myLabel];
[myImageView bringSubviewToFront: myLabel];

If you have just taken the UILabeland 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 contentVerticalAlignmentproperty 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.

注意:我已经检查了它的构造然后我发布了。它正在工作。