как отобразить значок или изображение в uilabel или uitextview (uitextfield) - PullRequest
1 голос
/ 02 сентября 2011

Может ли UILabel отображать значок или изображение??
Я создавал приложение для чата, которое должно показывать значок или изображение или пользовательское изображение в UILabel или UITextField, чтобы можно было отображать выражение или изображения.Как это сделать?

Ответы [ 4 ]

3 голосов
/ 02 сентября 2011
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 голос
/ 05 апреля 2016

в 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;
0 голосов
/ 02 сентября 2011

Вы можете использовать iphone emoji .Прочитайте это Iphone Emoji

0 голосов
/ 02 сентября 2011

Вы можете сделать это таким образом для 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];
...