gpt4 book ai didi

iOS - 检查图像是否存在于应用程序包中

转载 作者:行者123 更新时间:2023-11-28 22:49:06 24 4
gpt4 key购买 nike

如何根据字符串判断图像是否存在于主应用程序包中?例如,bundle 中是否有名为 image1.png 的图像?

最佳答案

NSBundle方法:

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

如果没有找到图片,将返回 nil。

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" ofType@"png"];
if(filePath.length > 0 && filePath != (id)[NSNull null]) {
UIImage *myImage = [UIImage imageWithContentsOfFile:filePath];
}

关于iOS - 检查图像是否存在于应用程序包中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12394237/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com