Add text to CALayer

前端 未结 7 1993
Happy的楠姐
Happy的楠姐 2020-11-29 19:28

Is it possible to add a UILabel to a CALayer without subclassing and drawing it in drawInContext:?

Thanks!

7条回答
  •  眼角桃花
    2020-11-29 20:13

    Your UILabel already has a CALayer behind it. If you are putting together several CALayers, you can just add the UILabel's layer as a sublayer of one of those (by using its layer property).

    If it's direct text drawing in a layer that you want, the UIKit NSString additions that Deepak points to are the way to go. For an example of this in action, the Core Plot framework has a Mac / iPhone platform-independent CALayer subclass which does text rendering, CPTextLayer.

提交回复
热议问题