+ (nullable UIImage *)imageNamed:(NSString *)name;
根據(jù)name生成圖片
系統(tǒng)有緩存,程序員無法回收
+ (nullable UIImage *)imageWithContentsOfFile:(NSString *)path;
根據(jù)路徑加載圖片
只要沒有強引用,就會回收,傳入全路徑,不能加載Assets里面的圖片
+ (nullable UIImage *)animatedImageWithImages:(NSArray<UIImage *> *)images duration:(NSTimeInterval)duration NS_AVAILABLE_IOS(5_0);
根據(jù)數(shù)組和持續(xù)時間生成動畫圖片
images:動畫圖片數(shù)組
duration:動畫持續(xù)時間
案例(動畫圖片)
- (void)setupUI {
//創(chuàng)建圖片數(shù)組
NSMutableArray *arrayM = [NSMutableArray array];
for (int i = 1; i <= 25; i++) {
//圖片名稱
NSString *imageName = [NSString stringWithFormat:@"father%03d",i];
//創(chuàng)建UIImage
UIImage *image = [UIImage imageNamed:imageName];
//添加到數(shù)組
[arrayM addObject:image];
}
//參數(shù)1:要動畫的圖片數(shù)組
//參數(shù)2:動畫持續(xù)時間
UIImage *img = [UIImage animatedImageWithImages:arrayM duration:2];
//創(chuàng)建UIImageView
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 150)];
//設(shè)置位置
iv.center = self.view.center;
//設(shè)置圖片
iv.image = img;
//添加到父容器
[self.view addSubview:iv];
}