美文网首页
文本混排,label显示图片

文本混排,label显示图片

作者: VickyLanLan | 来源:发表于2018-08-02 16:31 被阅读19次

    刚发现这个类好用NSTextAttachment图文混排,不用再去麻烦计算图片的位置去移动,简单实现button,label的图文混排的效果,记录一下。

        UIButton*zongheButton =[[UIButtonalloc]initWithFrame:CGRectMake(30,50,100,60)];

        [self.viewaddSubview: zongheButton];

        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@"综合排序"];

        NSTextAttachment *attch = [[NSTextAttachment alloc] init];

        attch.image= [UIImageimageNamed:@"offLine_phone"];

        attch.bounds=CGRectMake(5,0,20,15);

        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];

        [attriappendAttributedString:string];

        [attriaddAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, attri.length)];

        [zongheButtonsetAttributedTitle:attri forState:UIControlStateNormal];

    相关文章

      网友评论

          本文标题:文本混排,label显示图片

          本文链接:https://www.haomeiwen.com/subject/tzlsvftx.html