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 小时前
开源鸿蒙终端工具Termony构建HNP包指导手册Mac版
macos·开源·harmonyos
2501_9160088915 小时前
提高 iOS 应用逆向难度的工程实践,多工具联动的全栈安全方案
android·安全·ios·小程序·uni-app·cocoa·iphone
CXH72818 小时前
k8s-host-mac
macos·容器·kubernetes
德生coding19 小时前
linux系统多网卡共用一个MAC地址的使用问题
macos
2501_9159090620 小时前
iOS App 测试工具全景指南,构建从开发、性能到系统级调试的多工具协同测试体系
android·测试工具·ios·小程序·uni-app·iphone·webview
AskHarries20 小时前
RevenueCat 接入 Apple App Store 订阅全流程详解(2025 最新)
flutter·ios·app
ajassi20001 天前
开源 Objective-C IOS 应用开发(十三)通讯--Http访问
ios·开源·objective-c
游戏开发爱好者81 天前
Fiddler抓包工具完整教程 HTTPHTTPS抓包、代理配置与API调试实战技巧(开发者进阶指南)
前端·测试工具·ios·小程序·fiddler·uni-app·webview
m0_495562781 天前
iOS的蓝牙
macos·ios·cocoa
songgeb1 天前
[WWDC]Why is my app getting killed 学习笔记
ios