Drop cap with NSAttributedString

前端 未结 5 1662
误落风尘
误落风尘 2020-12-04 20:02

I would like to do a drop cap first character in a UILabel using the attributedText NSAttributedString property only. Like this:

<
5条回答
  •  醉酒成梦
    2020-12-04 20:37

    No, this cannot be done with an NSAttributedString and standard string drawing only.

    Since the drop cap is a property of a paragraph the CTParagraphStyle would have to contain the information about the drop cap. The only property in CTParagraphStyle that affects indentation of the start of the paragraph is kCTParagraphStyleSpecifierFirstLineHeadIndent, but that affects the first line only.

    There's just no way to tell the CTFramesetter how to calculate the beginnings for the second and more rows.

    The only way is to define your own attribute and write code to draw the string using CTFramesetter and CTTypesetter that acknowledge this custom attribute.

提交回复
热议问题