sizeWithFont method is deprecated. boundingRectWithSize returns an unexpected value

前端 未结 6 1369
傲寒
傲寒 2020-12-02 06:38

In iOS7, sizeWithFont is deprecated, so I am using boundingRectWithSize(which returns a CGRect value). My code:

 UIFont *fontText =         


        
6条回答
  •  执笔经年
    2020-12-02 07:26

    The @SoftDesigner's comment has worked for me

    CGRect descriptionRect = [description boundingRectWithSize:CGSizeMake(width, 0)
                                                           options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                                        attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12]}
                                                           context:nil];
    result = ceil(descriptionRect.size.height);
    

提交回复
热议问题