This question already has answers here:
iOS 7 sizeWithAttributes: replacement for sizeWithFont:constrainedToSize
                                
                                    (9个答案)
                                
                        
                                5年前关闭。
            
                    
如何使用sizeWithAttributes方法产生以下代码:

CGFloat labelWidth = [label.text sizeWithFont:label.font].width;


我需要标签宽度!

最佳答案

这样使用

CGSize size = [string sizeWithAttributes:
                       @{NSFontAttributeName:
                         [UIFont systemFontOfSize:17.0f]}];

关于ios - 用sizeWithAttributes替换已弃用的sizeWithFont ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22933739/

10-14 23:38