func resizeImgWithWidth(_fWidth:CGFloat){
self.enumerateAttribute(NSAttachmentAttributeName, in: NSMakeRange(0, self.length), options: []) { (pAny, pRange, stop) in
if(pAny !=nil){
letattachment = pAnyas!NSTextAttachment
letbounds0 = attachment.bounds
ifbounds0.width>fWidth{
letfNewHeight = bounds0.height*fWidth/bounds0.width
attachment.bounds=CGRect.init(origin: bounds0.origin, size:CGSize.init(width: fWidth, height: fNewHeight))
}
}
}
}
网友评论