学习iOS控件之UIImageView

  学习iOS控件之UIImageView

UIIamgeView是用来显示图片的,需要一个UIImage来装在图片,在UIImageView上显示,和UIButton之间的区别在于,默认情况下是不能点击的,不接受用户行为。UIImageView还可以用来播放序列图。

UIImageView的官网地址:https://developer.apple.com/reference/uikit/uiimageview 点击打开链接


    //控件初始化
    UIImageView *imageView = [[UIImageView alloc] init];
    
    //设置背景颜色
    imageView.backgroundColor = [UIColor redColor];
    
    //设置frame
    imageView.frame = CGRectMake(50, 50, 200, 246);
    
    //设置圆角
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 20;
    
    //设置边框颜色和大小
    imageView.layer.borderColor = [UIColor orangeColor].CGColor;
    imageView.layer.borderWidth = 2;
    
    //UIImage
    UIImage *image = [UIImage imageNamed:@"child"];
    imageView.image = image;
    
    //UIImageView默认不接受用户行为,YES打开用户行为
    imageView.userInteractionEnabled = YES;
    
    //设置中心点
    imageView.center = CGPointMake(200, 200);
    
    //添加手势
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImageView:)];
    [imageView addGestureRecognizer:singleTap];
    
    [self.view addSubview:imageView];
    
    
   
    //播放一系列图片
    UIImage *image1 = [UIImage imageNamed:@"one"];
    UIImage *image2 = [UIImage imageNamed:@"two"];
    UIImage *image3 = [UIImage imageNamed:@"three"];
    NSArray *imagesArray = @[image1,image2,image3];
    imageView.animationImages = imagesArray;
    
    //序列图播放时间
    imageView.animationDuration = 2;
    
    //播放多少遍,0表示无数遍
    imageView.animationRepeatCount = 0;
    
    // 开始播放
    [imageView startAnimating];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值