iOS开发之圆角指定
来源:互联网 发布:js秒杀倒计时代码 编辑:程序博客网 时间:2024/05/27 09:45
如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。
对于这种情况,Stackoverflow上提供了几种解决方案。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码。
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = view2.bounds;maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;
其中,
byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight
指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:
* UIRectCornerTopLeft* UIRectCornerTopRight* UIRectCornerBottomLeft* UIRectCornerBottomRight* UIRectCornerAllCorners
从名字很容易看出来代表的意思,使用“|”来组合就好了。
1 0
- iOS开发之圆角指定
- iOS控件之指定圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发之指定UIView的某几个角为圆角
- iOS开发技巧之:图片压缩成指定的大小
- iOS开发之UITableViewController指定刷新cell 或section
- ios 指定角度圆角
- ios开发-指定文件夹管理
- iOS开发 指定UIView的某几个角为圆角
- iOS开发--指定UIView的某几个角为圆角
- iOS开发--指定UIView的某几个角为圆角
- 常见HTTP状态码
- C++修饰构造函数的explicit关键字
- kali更新错误,解决方法.
- Spark学习之12:checkpoint
- 漫谈 Clustering (1): k-means
- iOS开发之圆角指定
- CTCI---8.2.1
- 局部特征图像描述
- 设计模式之Decorator Pattern
- TextView的一些高级显示
- tomcat 问题: "The APR based Apache Tomcat Native library which allows optimal perf
- web端图形绘制--VML--SVG
- 使用 dom4j 生成 XML指定编码格式
- adt, eclipse 查看版本号