首页 > 代码库 > 给图片设置圆角和圆形边框,添加点击事件

给图片设置圆角和圆形边框,添加点击事件

    //1.创建图片    _userImage = [[UIImageView alloc]init];  
  //2.设置图片圆角 _userImage.layer.cornerRadius = 33; _userImage.layer.masksToBounds = YES; //3.设置圆形边框 CALayer *layer = [_userImage layer]; layer.borderColor = [[UIColor whiteColor] CGColor]; layer.borderWidth = 2.0f; //4.给图片添加点击事件 _userImage.userInteractionEnabled = YES; UITapGestureRecognizer *userImageTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(userImageAction)]; [_userImage addGestureRecognizer: userImageTap];