NSAttributeString Height seems align wrong when use both image and text

236 views Asked by At

I have a uilabel in tableviewcell ,and the label use NSAttributeString to support both image and text. But I found when the label contains image or text only , the height of label is correct ,but when label contains image and text both ,the height seems not correct .the row height seems little more big than the actual height need

enter image description here

and if there is text or images only ,the height is right

enter image description here

and I was using my Own subclass from NSTextAttachment to construct image enter image description here

and the attachment code is like this enter image description here

1

There are 1 answers

0
ximmyxiao On

OK, this line of code seems work, but I still don't know why well [textAttributeString addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithFloat:-4] range:NSMakeRange(0, textAttributeString.length)];