iOS Framework代码中加载图片资源

在Framework中,加载UIImage(named:"icon.png")时,老是失败,

换成 UIImage(contentsOfFile: filePath) 也是不对:

if let filePath = Bundle.main.path(forResource: "icon", ofType: "png"){

icon = UIImage(contentsOfFile: filePath)

}

后来搜索发现,在Framework中,无法直接根据名字获得,

需要通过framework的bundle来加载

let bundle = Bundle(for: SomeClass.self)

if let filePath = bundle.path(forResource: "icon", ofType: "png"){

icon = UIImage(contentsOfFile: filePath)

}

相关推荐
忆江南14 小时前
iOS 深度解析
flutter·ios
没有故事的Zhang同学14 小时前
05-主题|事件响应者链@iOS-应用场景与进阶实践
ios
FeliksLv1 天前
尝试给Lookin 支持 MCP
ios
没有故事的Zhang同学1 天前
01-研究系统框架@Web@iOS | JavaScriptCore 框架:从使用到原理解析
ios
pe7er2 天前
macOS 应用无法打开(权限问题)解决方案
macos·mac
CocoaKier3 天前
苹果谷歌商店:如何监控并维护用户评分评论
ios·google·apple
iOS日常3 天前
iOS设备崩溃日志获取与查看
ios·xcode
wangruofeng3 天前
AI 助力 Flutter 3.27 升级到 3.38 完整指南:两周踩坑与实战复盘
flutter·ios·ai编程
iOS日常4 天前
Xcode 垃圾清理
ios·xcode
开心就好20254 天前
不越狱能抓到 HTTPS 吗?在未越狱 iPhone 上抓取 HTTPS
后端·ios