iOS开发-缓存图片到沙盒--思路
生活随笔
收集整理的這篇文章主要介紹了
iOS开发-缓存图片到沙盒--思路
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.圖片存儲到沙盒中
?
| 1 2 3 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); ????????NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", myI]];?? // 保存文件的名稱 ????????[UIImagePNGRepresentation(myImage)writeToFile: filePath??? atomically:YES]; |
2.在plist中保存路徑
?
| 1 2 3 4 5 6 7 8 | NSMutableDictionary *info = [[NSMutableDictionary alloc]init]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", conut_]];?? // 保存文件的名稱 [info setObject:filePath forKey:@"img"]; [specialArr addObject:info]; |
3.使用圖片
?
| 1 2 3 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"pic_%d.png", (int)current]];?? // 保存文件的名稱 UIImage *img = [UIImage imageWithContentsOfFile:filePath]; |
總結
以上是生活随笔為你收集整理的iOS开发-缓存图片到沙盒--思路的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: win7共享打印机设置的方法是什么
- 下一篇: 关于UIAlertActionStyle