[英]how to display an icon or image in a uilabel or uitextview(uitextfield)
Can a UILabel
display an icon or image? UILabel
显示图标或图像吗? ? ?
I was making a chat application, which needs to show icon or image or custom image in a UILabel
or UITextField
so that an expression or pictures can be displayed. 我正在制作一个聊天应用程序,它需要在UILabel
或UITextField
显示图标或图像或自定义图像,以便显示一个或多个表达式。 How to do this? 这个怎么做?
UITextView *textView = [[UITextView alloc]initWithFrame: self.view.frame];
textView.text = @"your text";
UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
imgView.image = [UIImage imageNamed: @"yourImage.png"];
[self.view addSubview: imgView];
[imgView addSubview: imgView];
in iOS >= 7: 在iOS> = 7中:
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"icon.png"];
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"text bla bla bla"];
[myString appendAttributedString:attachmentString];
self.label.attributedText = myString;
You can do it this way for UILabel
你可以这样对UILabel
这样做
labelname.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imagename"]];
Or to set image as background to your UITextView
或者将图像设置为UITextView
背景
UITextView *textView = [[UITextView alloc]initWithFrame: window.frame];
textView.text = @"text\n text\n text";
UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
imgView.image = [UIImage imageNamed: @"myImage.jpg"];
[textView addSubview: imgView];
[textView sendSubviewToBack: imgView];
[window addSubview: textView];
You can use iphone emoji . 你可以使用iphone表情符号 。 Read this Iphone Emoji 阅读此Iphone表情符号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.