iOS-圆角的另外两种实现方式

-(void)ImageV1{

    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(200, 200, 200, 200)];
    imageView.image = [UIImage imageNamed:@"1"];
    UIBezierPath * maskPath = [UIBezierPath bezierPathWithRoundedRect:imageView.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:imageView.bounds.size];
    CAShapeLayer * maskLayer = [[CAShapeLayer alloc]init];
    maskLayer.frame = imageView.bounds;
    maskLayer.path = maskPath.CGPath;
    imageView.layer.mask = maskLayer;
    [self.view addSubview:imageView];
}

-(void)ImageV2{

    UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(200, 400, 200, 200)];
    imageView.image = [UIImage imageNamed:@"1"];
    UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, NO, 1.0);
    [[UIBezierPath bezierPathWithRoundedRect:imageView.bounds cornerRadius:imageView.frame.size.width]addClip];
    [imageView drawRect:imageView.bounds];
    
    imageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.view addSubview:imageView];

}

你可能感兴趣的:(iOS-圆角的另外两种实现方式)