美文网首页
label 文本中添加图标

label 文本中添加图标

作者: 一米阳光k1992 | 来源:发表于2018-11-02 12:02 被阅读0次

    在Label 文本中添加图标

    NSMutableAttributedString *textAttrStr = [[NSMutableAttributedString alloc] initWithString:self.address];

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

            attach.image= [UIImageimageNamed:@"address_copy"];

            attach.bounds=CGRectMake(0, -3,16,16);//设置图片位置 (不太好用)设置间距无效果

            NSAttributedString *imgStr = [NSAttributedString attributedStringWithAttachment:attach];

            [textAttrStrappendAttributedString:imgStr];

            if(self.address.length>0) {

    //设置图片与文字间距

                [textAttrStraddAttribute:NSKernAttributeName value:@(4) range:NSMakeRange(self.address.length - 1, 1)];

            }

            self.customAddressLb.attributedText= textAttrStr;

    相关文章

      网友评论

          本文标题:label 文本中添加图标

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