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)

}

相关推荐
_瑞4 小时前
深入理解 iOS 渲染原理
前端·ios
Android出海12 小时前
iOS 出海新门槛:未成年人合规来了
ios·app store·ios开发·苹果开发者·ios开发者·ios出海
2501_9151063213 小时前
iOS 软件测试工具性能监控、日志分析 KeyMob、Instruments等
android·ios·小程序·https·uni-app·iphone·webview
木叶丸14 小时前
AI 编程概念与 Harness 工程实践入门
人工智能·flutter·ios
zzb158015 小时前
Zed 配置 Swift / iOS 开发
开发语言·ios·swift
全堆鸿蒙1 天前
25 数据库设计与表结构规划:5 张表的设计思路
数据库·华为·cocoa·harmonyos
colman wang1 天前
Git指令(Mac)
git·macos
黑科技iOS上架1 天前
如何解决AppStore Guideline 5.6被拒
经验分享·ios·ai编程
韩曙亮2 天前
【Flutter】iOS 网络权限设置 ① ( WLAN/蜂窝全局联网权限设置 )
网络·flutter·ios·网络权限
Geek-Chow2 天前
Mobile App Certificate Pinning: Underlying Principle and a Swift Example
开发语言·ios·swift·安全架构