UILabel
可以显示图标或图片吗? ?
我正在制作一个聊天应用程序,它需要在UILabel
或UITextField
中显示图标或图像或自定义图像,以便显示一个或多个表达式。怎么做?
答案 0 :(得分:3)
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];
答案 1 :(得分:1)
> = 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;
答案 2 :(得分:0)
您可以通过UILabel
labelname.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imagename"]];
或者将图片设置为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];
答案 3 :(得分:0)
您可以使用 iphone表情符号。阅读此Iphone Emoji