UIImageView簡單使用方法:
//初始化
UIImageView *imageView = [ [UIImageView alloc] initWithFrame:CGRectMake(20, 20, 200, 200) ];
UIImageView *imageView = [ [UIImageView alloc] initWithImage: (image) ];
UIImageView *imageView = [ [UIImageView alloc] initWithImage: (image) highlightedImage:(image2) ];
//設置中間點位置
imageView.center = CGPointMake(CGPoint x, CGPoint y);
//是否隱藏
imageView.hidden = YES;
//設置透明度
imageView.alpha = 0.5;
//添加圖片
imageView.image = image;
//高亮時圖片
imageView.highlightedImage = image;
//視圖的圖層上的子圖層,如果超出父圖層的部分就截取掉
imageView.layer.masksToBounds = YES;
//設置圓角
imageView.layer.cornerRadius = 10; //如果變成園,則爲半徑
//設置邊框大小
imageView.layer.borderWidth = 1;
//設置邊框顏色
imageView.layer.borderColor = [UIColor redColor];
//設置圖片的顯示方式 居中,縮放等等
imageView.contentMode = UIViewContentModeScaleAspectFill;
typedef enum {
UIViewContentModeScaleToFill;
UIViewContentModeScaleAspectFit;
UIViewContentModeScaleAspectFill;
UIViewContentModeRedraw
UIViewContentModeCenter
UIViewContentModeTop
UIViewContentModeBottom
UIViewContentModeLeft
UIViewContentModeRight
UIViewContentModeTopLeft
UIViewContentModeTopRight
UIViewContentModeBottomLeft
UIViewContentModeBottomRight
} UIViewContentModeType;
//添加事件
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [ [UITapGestureRecognizer alloc] initWithTarget: self action: @selector(tapImageView:) ];
[ imageView addGestureRecognizer: singleTap];
//圖片播放
UIImage *image1 = [UIImage imageNamed:@"image1.png"];
UIImage *image2 = [UIImage imageNamed:@"image2.png"];
UIImage *image3 = [UIImage imageNamed:@"image3.png"];
NSArray *imageArr = @[image1, image2, image3];
imageView.animationImages = imageArr;
imageView.animationDuration = [imageArr count]; //播放圖片持續時間
imageView.animationRepeatCount = 0; //播放多少遍,0表示無數遍
[imageView startAnimating]; //開始播放
[imageView stopAnimating]; //停止播放