用sizeWithAttributes()方法计算文本size Swift

最新版本Swift要这么写:

NSString(string: str).size(withAttributes: [NSAttributedStringKey.font: UIFont.systemFont(ofSize: UIFont.systemFontSize)])

1.先把str转成NSString类型

2.用.size(withAttributes: )方法计算

猜你喜欢

转载自blog.csdn.net/weixin_42012181/article/details/80858188