// 动态计算_shortLabel的文字宽度
CGSize size = [_shortLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:_shortLabel.font,NSFontAttributeName, nil]];
NSLog(@"%f %f",size.width,size.height);
本文介绍了一种使用Objective-C动态计算UILabel中文字宽度的方法。通过CGSize的sizeWithAttributes方法结合NSDictionary来设置字体属性,实现对UILabel内文字尺寸的精确测量。
// 动态计算_shortLabel的文字宽度
CGSize size = [_shortLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:_shortLabel.font,NSFontAttributeName, nil]];
NSLog(@"%f %f",size.width,size.height);
2757

被折叠的 条评论
为什么被折叠?