UILabel default kerning different from CATextLayer

后端 未结 3 2159
天命终不由人
天命终不由人 2021-02-08 00:19

I have a UILabel with the string \'LA\'. I also have a CATextLayer with the same characters in an NSAttributedString assigned to its

3条回答
  •  没有蜡笔的小新
    2021-02-08 01:00

    Well Core Text is really different when compared to drawing strings using UIKit, probably because it comes from Core Foundation and not AppKit or UIKit. I do understand your requirements to use a label for doing the metrics hard job on a string. The only solution for me is to match the kerning of UILabel in the attributed string, unfortunately I don't know the exact value but you can use this property to change that value kCTKernAttributeName. You should pay attention also for the interline that could be not the same.
    Forcing that value to the matching kerning you could have the correct behavior. If you want the opposite (match CT kerning) you should do some math an later apply to the label a UIEdgeInset to math the correct label.
    Hope this helps.

提交回复
热议问题