Replacement for deprecated sizeWithFont: in iOS 7?

后端 未结 20 1283
难免孤独
难免孤独 2020-11-22 08:49

In iOS 7, sizeWithFont: is now deprecated. How do I now pass in the UIFont object into the replacement method sizeWithAttributes:?

20条回答
  •  没有蜡笔的小新
    2020-11-22 08:54

    You can still use sizeWithFont. but, in iOS >= 7.0 method cause crashing if the string contains leading and trailing spaces or end lines \n.

    Trimming text before using it

    label.text = [label.text stringByTrimmingCharactersInSet:
                 [NSCharacterSet whitespaceAndNewlineCharacterSet]];
    

    That's also may apply to sizeWithAttributes and [label sizeToFit].

    also, whenever you have nsstringdrawingtextstorage message sent to deallocated instance in iOS 7.0 device it deals with this.

提交回复
热议问题