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)

}

相关推荐
二流小码农7 小时前
2026年,在鸿蒙生态里,继续深耕自己
android·ios·harmonyos
2501_915106327 小时前
iPhone 文件管理,如何进行应用沙盒文件查看
android·ios·小程序·https·uni-app·iphone·webview
追夢秋陽10 小时前
MacOS app打包Dmg线下分发测试及公证shell脚本
macos·shell·dmg·cocoa打包·打包脚本
追夢秋陽11 小时前
MacOS 通过Shell 脚本一步到位配置nginx+Php环境
nginx·macos·php·一站式配置
专业开发者11 小时前
Wi-Fi 技术学习:一文读懂WPA2四次握手的密钥体系与交互逻辑
网络·学习·macos
符哥200813 小时前
iOS 开发中常用的第三方库 / 框架列表
ios
2501_9159214313 小时前
iOS 抓包怎么绕过 SSL Pinning 证书限制,抓取app上的包
android·网络协议·ios·小程序·uni-app·iphone·ssl
qq_1728055913 小时前
Mac book pro 清理系统数据270G的硬盘空间
macos
rock——you1 天前
macos如何升级到指定版本,而不是默认最新的版本。我的现在为15.3,如何升级到15.4,而不是最新的15.54
macos
打倒苦瓜蛋1 天前
Mac typora安装 破解教程!!!
macos