English 中文(简体)
在iPhone应用程序中捆绑应用程序图像的最佳位置
原标题:Best place to bundle your application images in iPhone app

存储数十张甚至数百张png图像的最佳实践是什么,这些图像应该捆绑在iphone应用程序中?

是否有方法使用UIImagePickerController访问它们,或者我必须自己创建其他方法来访问它们?

此外,捆绑它们的最佳实践是什么?应用内捆绑还是让应用从服务器下载?

最佳回答

如果你需要离线使用这些图像,我会把它放在你的应用程序包中。我会创建一个物理文件夹并将其拖动到Xcode项目中,然后选择创建文件夹引用,该引用应显示为蓝色文件夹图标。把你所有的png文件放在那个文件夹里。

要获取该文件夹中所有文件的列表,请执行以下操作:

NSString *filesPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"pngfolder"];  // where pngfolder is the folder as described above.
NSArray *filesList = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filesPath error:nil];

要读取索引i处的单个图像文件,例如上面的filesList数组中的文件:

NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:[filesList objectAtIndex:i]];
UIImage *img = [[UIImage alloc]initWithContentsOfFile:sourcePath];
问题回答

所有大公司做的最好的方法是。。将所有小图像转换为单个大图像,然后在客户端渲染您想要的任何图像。

你可以找到很多很好的例子。。我觉得这很有趣http://yuilibrary.com/yui/docs/dd/photo-browser.html#slider-以及样式表。。查看附带yui捆绑包的js文件,以及捆绑为单个图像的所有图像





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签