1、从内存
把图片从硬盘读到内存
UIImage *image = [UIImage imageNamed:@"2.png"];
把读到内存的图片image对象赋值给imageView的image属性
2、从硬盘
找到文件的路径
NSString *imagePath = [[NSBundle mainBundle] pathForResource;@“” ofType@“.png”];
从路径中取图片,参数是文件的路径
UIImage *lastImage = [UIImage imageWithContentsOfFiel:imagePath];
剩下的就是创建UIImageView
imageNamed和iamgeWithContentsOfFile优缺点
优点 缺点
imageNamed 从缓存读,快 占缓存
imageWithContentsOfFile 不占缓存 慢
使用规则:小图片,重复使用次数多的图片,用imageNaemd
大图片,不怎么用的图片用imageWithContentsOfFile