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];
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];
相关文章推荐
- iOS设置圆角的几种方式
- IOS 条件判断的几种形式
- iOS:NSDate的主要几种时间形式
- iOS中设置圆角的几种方法示例
- iOS开发中UITableView和UItableViewCell的几种形式
- JSON的几种调用形式
- C#数据类型转换的几种形式
- XML文档定义有几种形式?它们之间有何本质区别?解析XML文档有哪几种方式?
- 4.4.2 复杂属性的几种标记形式
- DATE 几种显示形式
- 企业组织机构几种形式
- 实现圆角的几种方式
- XML文档定义有几种形式?它们之间有何本质区别?解析XML文档有哪几种方式
- 网页实现圆角的几种方式
- C#数据类型转换的几种形式
- 关于绑定的几种形式
- Object转为String的几种形式(转
- 与数据库连接从中读取数据的几种常见的形式
- for语句中的几种分隔符形式小结
- 表单提交按钮图片形式的几种写法