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)

}

相关推荐
界面开发小八哥3 小时前
支持iOS与Android!SciChart开源金融图表库助力高效开发交易应用
android·ios·数据分析·数据可视化·图表工具·scichart
returnShitBoy4 小时前
Swift 的主要特点和优点或缺点是什么?
开发语言·ios·swift
柯基的小屁墩5 小时前
mac|使用scrcpy实现无线Android投屏
macos
我不是代码教父5 小时前
[原创](现代Delphi 12指南): 设置、运行和调试你的第一个macOS应用程序.
macos·delphi
搬砖天才、5 小时前
日常记录-群晖nas的docker注册表被墙,用Mac电脑的docker拉取镜像并安装到nas中
macos·docker·容器
OKXLIN16 小时前
XCode集成第三方framework步骤
ide·macos·framework·xcode
鸿蒙布道师20 小时前
鸿蒙NEXT开发资源工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
season_zhu1 天前
iOS开发:关于路由
ios·架构·swift
yinshuilan1 天前
Mac提示无法打开应用程序DBeaver
macos
鸿蒙布道师1 天前
鸿蒙NEXT开发设备相关工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei