IOS 计算富文本的高度方法

方式一:

objectivec 复制代码
NSMutableAttributedString *attStr = [NSMutableAttributedString new];

CGSize attSize = [attStr boundingRectWithSize:CGSizeMake(UIScreen.mainScreen.bounds.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;

CGFloat height = size.height;

NSMutableAttributedString *attStr = [NSMutableAttributedString new];

CGSize attSize = [attStr boundingRectWithSize:CGSizeMake(UIScreen.mainScreen.bounds.size.width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading context:nil].size;

CGFloat height = size.height;

方式二:

objectivec 复制代码
NSMutableAttributedString *attStr = [NSMutableAttributedString new];

CGFloat height = [label sizeThatFits:CGSizeMake(UIScreen.mainScreen.bounds.size.width, CGFLOAT_MAX)].height;

NSMutableAttributedString *attStr = [NSMutableAttributedString new];

CGFloat height = [label sizeThatFits:CGSizeMake(UIScreen.mainScreen.bounds.size.width, CGFLOAT_MAX)].height;

相关推荐
2501_9159090610 小时前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
@大迁世界11 小时前
液态玻璃屏正在侵蚀你的电池
macos·ios·objective-c·cocoa
pop_xiaoli12 小时前
【iOS】类与对象底层
macos·ios·objective-c·cocoa·xcode
sp42a12 小时前
NativeScript iOS 平台开发技巧
ios·nativescript·app 开发
2501_9159214313 小时前
常用iOS性能测试工具大全及使用指南
android·测试工具·ios·小程序·uni-app·cocoa·iphone
for_ever_love__13 小时前
Objecgtive-C学习实例对象,类对象, 元类对象与 isa指针
c语言·学习·ios
一招定胜负14 小时前
视频转写+LLM分析:课堂录音自动化处理实现
macos·ios·xcode
2501_9159184114 小时前
有没有Xcode 替代方案?在快蝎 IDE 中完成 iOS 开发的过程
ide·vscode·ios·个人开发·xcode·swift·敏捷流程
blackorbird14 小时前
通过攻陷合法网站传播的新型iOS漏洞利用工具包DarkSword
macos·ios·objective-c·cocoa
for_ever_love__16 小时前
Objective-C学习 NSSet 和 NSMutableSet 功能详解
开发语言·学习·ios·objective-c