How to draw images among rich-text with CoreText? (iOS)

后端 未结 2 1503
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-30 12:17

I can draw rich-text with Core Text, the problem is placing images flowing with the text. (iOS SDK 4.1)

I\'m try to drawing some kind of rich-text. Problem is designer p

2条回答
  •  没有蜡笔的小新
    2021-01-30 12:30

    I got solution.

    The key of laying out non-text content is CTRunDelegate. Core Text does not support non-text content, so you have to make blank spaces for them, and draw or place them yourself later.

    A part of NSAttributedString attributed with kCTRunDelegateAttributeName will call registered callback to determine width of each glyph. This will let you make blank space for each non-text object.

    However, after drawing the text with Core Text, the layout information stored with frame/line/run will invalidated. So you have to draw/place non-text contents after layout with framesetter/typesetter, but before drawing.

    This link describes basic usage of CTRunDelegate:
    How to use CTRunDelegate in iPad?


    There is a problem with Core Text. Originally, CTRunDelegate designed to support variable width and vertical alignment via CTRunDelegateCallbacks.getAscent and CTRunDelegateCallbacks.getDescent. But vertical alignment feature doesn't work currently. This might be a bug.

    I described this problem here: Aligning multiple sized text vertical center instead of baseline with Core Text in iOS

    If you have informations about this problem, please see my question at the link.

提交回复
热议问题