美文网首页
iOS-圆角的另外两种实现方式

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

作者: 良人不归_墨染锦年 | 来源:发表于2018-05-13 21:32 被阅读0次
-(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-圆角的另外两种实现方式

      本文链接:https://www.haomeiwen.com/subject/dskrdftx.html