如何在UILabel实现图片文字混合显示

 

注意:未经本人同意,请勿转发

 

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0    , 100, 200, 44)];

[self.view addSubview:label];

NSMutableAttributedString *goalTipStr = [[NSMutableAttributedString alloc]initWithString:@"123456"];
NSTextAttachment *alertImg = [[NSTextAttachment alloc]init];
alertImg.image = [UIImage imageNamed:@"!_gray"];
alertImg.bounds=CGRectMake(0, -2, 13, 13);
NSAttributedString *imgStr = [NSAttributedString attributedStringWithAttachment:alertImg];
[goalTipStr insertAttributedString:imgStr atIndex:0];


label.text = goalTipStr ;
           

 

效果图。。。。。

 

posted @ 2016-08-02 10:55  落花伊人  阅读(433)  评论(0编辑  收藏  举报