lud*_*udo 17 iphone cocoa objective-c
当我使用包中的路径创建图像时,这就是我正在做的事情:
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"jpg"]];
Run Code Online (Sandbox Code Playgroud)
我想要做的是尝试找到我的图像的路径,但不使用扩展名,而不使用'ofType'(因为我的图像的名称和她的扩展名存储在我的数据库中)类似的东西:
UIImage *image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image.jpg"]];
Run Code Online (Sandbox Code Playgroud)
但我不知道该怎么做.
最好的祝福,
Tho*_*ing 41
为什么不拆分从DB获得的字符串?
NSString* fullFileName = @"image.jpg";
NSString* fileName = [[fullFileName lastPathComponent] stringByDeletingPathExtension];
NSString* extension = [fullFileName pathExtension];
Run Code Online (Sandbox Code Playgroud)
现在你可以简单地使用:
[[NSBundle mainBundle] pathForResource:fileName ofType:extension]];
Run Code Online (Sandbox Code Playgroud)
Bro*_*son 24
您可以轻松使用NSBundle方法而不传递扩展名,只需传递nil进行扩展即可.
[[NSBundle mainBundle] pathForResource:@"image.jpg" ofType:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12185 次 |
| 最近记录: |