Resize CATextLayer to fit text on iOS

后端 未结 4 1806
囚心锁ツ
囚心锁ツ 2020-12-29 05:01

All my research so far seems to indicate it is not possible to do this accurately. The only two options available to me at the outset were:

a) Using a La

4条回答
  •  梦毁少年i
    2020-12-29 06:00

    I have a much easier solution, that may or may not work for you.

    If you aren't doing anything special with the CATextLayer that you can't do a UILabel, instead make a CALayer and add the layer of the UILabel to the CALayer

    UILabel*label = [[UILabel alloc]init];
    
    //Do Stuff to label
    
    CALayer *layer = [CALayer layer];
    
    //Set Size/Position
    
    [layer addSublayer:label.layer];
    
    //Do more stuff to layer
    

提交回复
热议问题