您的位置:首页 > 移动开发 > IOS开发

IOS 圆角的几种形式

2016-10-09 09:45 134 查看
1:利用视图的layer 的 cornerRadius 属性

   UIImageView *
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(200, 200, 200, 200)];

   imageView.image = [UIImage imageNamed:@"1"];
   imageView.layer.cornerRadius = imageView.frame.size.width
2:利用CAShapeLayer
做切割。

    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];
3:利用画图的形式

    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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: