sizeWithFont method is deprecated. boundingRectWithSize returns an unexpected value

前端 未结 6 1370
傲寒
傲寒 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:20

    If I understand correctly, you are using boundingRectWithSize: just as a way of getting the size you would get with sizeWithFont (meaning you want directly the CGSize, not the CGRect)?

    This looks like what you are looking for :

    Replacement for deprecated sizeWithFont: in iOS 7?

    They are using sizeWithAttributes: to get the size, as a replacement for sizeWithFont.

    Do you still get the wrong size using something like this :

    UIFont *fontText = [UIFont fontWithName:[AppHandlers zHandler].fontName size:16];
                        // you can use your font.
    
    expectedLabelSize = [myString sizeWithAttributes:@{NSFontAttributeName:fontText}];
    

提交回复
热议问题