技术栈

iOS Framework代码中加载图片资源

xinyu3912025-02-27 16:07

在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)

}

上一篇:Flutter系列教程之(5)——常用控件Widget的使用示例
下一篇:第二十四:5.2【搭建 pinia 环境】axios 异步调用数据
相关推荐
iOS门童
1 天前
macOS 应用"已损坏"无法打开?一文搞懂 Gatekeeper 与解决方案
macos
NPE~
1 天前
[工具分享]Maccy —— 优雅的 macOS 剪贴板历史管理工具
macos·教程·工具·实用工具
忙碌544
1 天前
OpenTelemetry实战指南:构建云原生全链路可观测性体系
ios·flink·apache·iphone
差不多程序员
1 天前
Mac安装OpenClaw-cn保姆级教程
macos
dzl84394
1 天前
mac 安装python
开发语言·python·macos
Bruce_Liuxiaowei
1 天前
在 macOS 上通过 Docker 本地安装 OpenClaw 完整教程
macos·docker·容器·openclaw
阿捏利
1 天前
详解Mach-O(十五)Mach-O __DATA_CONST
macos·ios·c/c++·mach-o
ShikiSuen
1 天前
macOS 的 CpLk 中英切换卡顿的元凶在 InputMethodKit 本身
macos
热门推荐
01GitHub 镜像站点02【OpenClaw 本地实战 Ep.3】突破瓶颈:强制修改 openclaw.json 解锁 32k 上下文记忆03Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services04OpenClaw 使用和管理 MCP 完全指南05AI Agent 平台横评:ZeroClaw vs OpenClaw vs Nanobot06Clawdbot部署教程:解决‘gateway token missing’授权问题的完整步骤07AI 规范驱动开发“三剑客”深度对比:Spec-Kit、Kiro 与 OpenSpec 实战指南08OpenClaw 安装之(三)DeepSeek模型接入配置和详细配置参数09AI agent:介绍 ZeroClaw 安装,使用10让 Trae IDE 智能体 “读懂”文档 Excel+PDF+DOCX :mcp-documents-reader 工具使用指南