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)

}

相关推荐
2501_915909061 小时前
深度解析 iOS 内存占用,构建多工具协同的内存诊断、监控与优化体系
android·ios·小程序·https·uni-app·iphone·webview
longforus3 小时前
Flutter iOS 真机部署异常经验(Android Studio 提示无法运行,但 Xcode 可正常运行)
flutter·ios·android studio
为什么不问问神奇的海螺呢丶3 小时前
n9e categraf 监控项配置文件
ios·iphone
2501_915918413 小时前
iOS CPU 使用率深度分析,多工具协同定位高占用瓶颈的工程化方法
android·ios·小程序·https·uni-app·iphone·webview
2501_915106323 小时前
如何防止资源文件被替换?一套针对 iOS App 的多层资源安全方案
android·安全·ios·小程序·uni-app·iphone·webview
尽兴-3 小时前
MacOS 一键清理指定目录下老旧node_modules
macos
2501_915918413 小时前
IPA 一键加密工具的真实工程化实践 构建可自动化、可扩展的 iOS 应用安全体系
android·安全·ios·小程序·uni-app·自动化·iphone
九天轩辕3 小时前
基于 Qt 和 libimobiledevice 的跨平台 iOS 设备管理工具开发实践
开发语言·qt·ios
元气小嘉3 小时前
小程序开发中ios和安卓问题
android·ios