ios - 如何迭代 Stickers.xcassets 或从 xcassets 获取图像?
<p><p>我正在开发自定义贴纸应用程序扩展,我想循环访问我的 Sticker.xcassets 文件夹,而不是设置固定的 for 循环。 </p>
<p>例如:</p>
<pre><code>func getStickers() {
for index in 1...16 {
addSticker(location: "\(index)", description: "\(index)")
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可能知道您不使用字符串文字路径访问项目文件夹中的文件。相反,您使用 NSBundle 提供的功能。令人高兴的是,这些包括可以满足您的需求的功能。查看 NSBundle 的开发者引用:</p>
<p> <a href="https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html" rel="noreferrer noopener nofollow">https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html</a> </p>
<p>我认为您希望从本文档中获得的 list 是 3-11,它描述了如何从 bundle 中提取给定类型的所有 Assets :</p>
<pre><code>CFArrayRefbirdURLs;
// Find all of the JPEG images in a given directory.
birdURLs = CFBundleCopyResourceURLsOfType( mainBundle,
CFSTR("jpg"),
CFSTR("BirdImages") );
</code></pre>
<p>希望有帮助!</p></p>
<p style="font-size: 20px;">关于ios - 如何迭代 Stickers.xcassets 或从 xcassets 获取图像?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39561253/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39561253/
</a>
</p>
页:
[1]