OGeek|极客世界-中国程序员成长平台

标题: ios - 如何迭代 Stickers.xcassets 或从 xcassets 获取图像? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:33
标题: ios - 如何迭代 Stickers.xcassets 或从 xcassets 获取图像?

我正在开发自定义贴纸应用程序扩展,我想循环访问我的 Sticker.xcassets 文件夹,而不是设置固定的 for 循环。

例如:

func getStickers() {

    for index in 1...16 {
        addSticker(location: "\(index)", description: "\(index)")
    }
}



Best Answer-推荐答案


您可能知道您不使用字符串文字路径访问项目文件夹中的文件。相反,您使用 NSBundle 提供的功能。令人高兴的是,这些包括可以满足您的需求的功能。查看 NSBundle 的开发者引用:

https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html

我认为您希望从本文档中获得的 list 是 3-11,它描述了如何从 bundle 中提取给定类型的所有 Assets :

CFArrayRef  birdURLs;

// Find all of the JPEG images in a given directory.
birdURLs = CFBundleCopyResourceURLsOfType( mainBundle,
                CFSTR("jpg"),
                CFSTR("BirdImages") );

希望有帮助!

关于ios - 如何迭代 Stickers.xcassets 或从 xcassets 获取图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39561253/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4