【UIImage】和【UIImageView】
UIImage -->NSObject
UIImageView-->UIView
一.UIImage的创建方式
1、通过图片姓名创建
imageNamed的优点是当加载时会缓存图片到本地。所以当图片会频繁的使用时,那么用imageNamed的方法会比较好。
+ (UIImage *)imageNamed:(NSString *)name; //会将图片读到内存中
2、根据图片的路径获取图片创建
//先获得图片在App包内的路径
NSString *path=[[NSBundle mainBundle]pathForResource:@"DOVE 1" ofType:@"png"]
+ (UIImage *)imageWithContentsOfFile:(NSString *)path;
imageWithContentsOfFile:仅加载图片,图像数据不会缓存。因此对于较大的图片以及使用情况较少时,那就可以用该方法,降低内存消耗
3.用作两张图一张默认,一张高亮
UIImageView *im = [UIImageView alloc]initWithImage:@"" highlightedImage:@""];
4.二进制流创建
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"www.baid.du"]];
UIImage *im = [UIImage imageWithData:data];
二.图片视图填充模式
@property(nonatomic)UIViewContentMode contentMode;枚举
default is UIViewContentModeScaleToFill
UIViewContentModeScaleToFill 拉伸填满,缺省
UIViewContentModeScaleAspectFit 按比例填充
UIViewContentModeScaleAspectFill 按比例填满
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
三.图片视图的动画效果
//设置动画图片数组
imageView.animationImages = array;
//设置动画时间,是全部图片切换一次的时间
imageView.animationDuration = 1.5;
//设置动画重复次数,设为0是无限次
imageView.animationRepeatCount = 0;
//启动动画
[imageView startAnimating];
//停止动画
[imageView stopAnimating];
四. 动画属性
imageOritentation:图片方向
size:图片带下
scale:图片比例
resizingMode:图片显示方式 枚举类型
images:图片数组
duration: 动画时长