ios UIImageView简单使用

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];  //停止播放

猜你喜欢

转载自2914905399.iteye.com/blog/2299861