如何在uilabel或uitextview中显示图标或图像(uitextfield)

时间:2011-09-02 03:19:28

标签: iphone uitextfield uilabel

UILabel可以显示图标或图片吗? ?
我正在制作一个聊天应用程序,它需要在UILabelUITextField中显示图标或图像或自定义图像,以便显示一个或多个表达式。怎么做?

4 个答案:

答案 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)

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;

答案 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