UI控件(UIImageView)

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad]; image1_ = [UIImage imageNamed:@"scene_in.jpg"];
image2_ = [UIImage imageNamed:@"scene_out.jpg"]; imageView_ = [[UIImageView alloc]initWithImage:image1_];
[imageView_.image setAccessibilityIdentifier:@"image1"];
imageView_.frame = CGRectMake(, , , ); //[imageView sizeToFit]; 设置视图与图片大小一致 //设置图片为圆角
imageView_.layer.masksToBounds = YES;
imageView_.layer.cornerRadius = 5.0; //设置图片的透明度
imageView_.alpha = 0.1; //是否隐藏该图像
imageView_.hidden = NO; //增加点击响应事件
imageView_.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickImage)];
[imageView_ addGestureRecognizer:singleTap]; [self.view addSubview:imageView_]; } -(void)onClickImage{
//切换图片显示
NSLog(@"%@", imageView_.image.accessibilityIdentifier);
if([imageView_.image.accessibilityIdentifier isEqualToString:@"image1"]){
[imageView_ setImage:image2_];
[imageView_.image setAccessibilityIdentifier:@"image2"];
}else{
[imageView_ setImage:image1_];
}
} @end
上一篇:6. UIImageView 的使用


下一篇:UIImageView 自带动画+N张图片实现很炫的动画