iOS Why do NSTextAttachment disappear when setting NSBaselineOffsetAttributeName?

前端 未结 1 1088
误落风尘
误落风尘 2021-02-06 04:14

\"before\"

I want to align the NSTextAttachment to the center of the text, so I set NSBaselineOffsetAttributeName

1条回答
  •  悲&欢浪女
    2021-02-06 05:10

    I finally solve it by adding another attribute NSParagraphStyleAttributeName

        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.minimumLineHeight = lineheight; //line height equals to image height
        [attributes setValue:paragraphStyle forKey:NSParagraphStyleAttributeName];
    

    don't change the image's offset, just set the text's offset.

    0 讨论(0)
提交回复
热议问题