常用方法
// (1)
创建
UIImageView *imageView = [[UIImageView alloc ] init];
UIImage *image = [UIImage imageNamed:@"image_photo"];
imageView.image = image;
// (2)
设置圆角
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 10;
// (3)
设置边框颜色和大小
imageView.layer.borderColor = [UIColor orangeColor].CGColor;
imageView.layer.borderWidth = 2;
// (4)contentMode
属性:当图片小于
imageView
的大小处理图片显示
imageView.contentMode = UIViewContentModeScaleAspectFit;
/*
这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下几个常量可供设定:
UIViewContentModeScaleToFill,
UIViewContentModeScaleAspectFit,
UIViewContentModeScaleAspectFill,
UIViewContentModeRedraw,
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
*/
// (5)
为图片添加单击事件:一定要先将
userInteractionEnabled
置为
YES
,这样才能响应单击事件
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
[imageView addGestureRecognizer:singleTap];
// (6)
或者显示图片
imageView.hidden = YES;//
或者
NO;
// (7)
设置透明度
imageView.alpha =0.5;
// (8)
设置高亮时显示的图片
imageView.highlightedImage = [UIImage imageNamed:@"image_photo"];
//
设置正常显示的图片
imageView.image = [UIImage imageNamed:@"image_photo"];
// (9)
帧动画
UIImage *image1 = [UIImage imageNamed:@"homeNaviLeftBtn"];
UIImage *image2 = [UIImage imageNamed:@"homeNaviRightBtn"];
UIImage *image3 = [UIImage imageNamed:@"image_photo"];
NSArray *imagesArray = @[image1,image2,image3];
imageView.animationImages = imagesArray;
//
设定所有的图片在多少秒内播放完毕
imageView.animationDuration = [imagesArray count];
//
不重复播放多少遍,
0
表示无数遍
imageView.animationRepeatCount = 0;
//
开始播放
[imageView startAnimating];