美文网首页iOS Developer
UILabel中加载富文本时处理富文本图片的大小问题

UILabel中加载富文本时处理富文本图片的大小问题

作者: 白极翁 | 来源:发表于2017-02-10 13:20 被阅读295次
描述:

当UILabel加载富文本的时候,富文本中有图片,图片的大小超出屏幕的宽度时,可以调整图片的大小

//遍历富文本得到NSTextAttachment类,改变图片的大小
    [self.descriptionString enumerateAttribute:NSAttachmentAttributeName inRange:NSMakeRange(0, self.descriptionString.length) options:0 usingBlock:^(id  _Nullable value, NSRange range, BOOL * _Nonnull stop) {
       
        if ([value isKindOfClass:[NSTextAttachment class]]) {
            NSTextAttachment * attachment = value;
            CGFloat height = attachment.bounds.size.height;
            attachment.bounds = CGRectMake(0, 0, kScreenWidth-20, height);
        }
        
    }];

相关文章

网友评论

    本文标题:UILabel中加载富文本时处理富文本图片的大小问题

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