我们知道, 如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。

对于这种情况,Stackoverflow上提供了几种解决方案 。其中最简单优雅的方案,就是使用UIBezierPath。下面给出一段示例代码:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(120,10,80,80)];

view.backgroundColor = [UIColor redColor];

[self.view addSubview:view];

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10,10)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];

maskLayer.frame = view.bounds;

maskLayer.path = maskPath.CGPath;

view.layer.mask = maskLayer;

其中,

byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight

指定了需要成为圆角的角。该参数是UIRectCorner类型的,可选的值有:

* UIRectCornerTopLeft

* UIRectCornerTopRight

* UIRectCornerBottomLeft

* UIRectCornerBottomRight

* UIRectCornerAllCorners

从名字很容易看出来代表的意思,使用“|”来组合就好了。

最新文章

  1. 【转】js实现复制到剪贴板功能,兼容所有浏览器
  2. 新特性AAtitti css3 新特性attilax总结titti css
  3. Cache-Aside Pattern解析
  4. 通过设置虚拟机(ubantu15.10)的分辨率达到全屏效果
  5. hdu3033 分组背包
  6. Android调用系统关机与重启功能
  7. 怎样改动Myeclipse10.7的Servlet模板
  8. R0~R16寄存器作用(转)
  9. CentOS7 安装sentry(最新)
  10. cnblog 模板 SimpleMemory 个性化设置代码备份
  11. zabbix监控实战<3> 之自定义监控实例
  12. A2D JS框架 - Web API CSRF保护实现
  13. 爬虫(三)之scrapy核心组件
  14. maven项目出现红色感叹号报错
  15. 日期时间函数 mysql 和sqlserver 中对于常用函数的日期和时间函数的区别
  16. agc007D - Shik and Game(dp 单调性)
  17. windows下 jemalloc编译
  18. pkg_config找不到库
  19. 在初学Flask中遇到的小问题。
  20. Easy File Sharing Web Server 6.9远程溢出漏洞

热门文章

  1. 获取oracle当前系统设置了哪些事件
  2. 04-plis属性列表
  3. Codeforces 940F Machine Learning 带修改莫队
  4. isatty
  5. 【 Linux】脚本导入格式
  6. 请求参数中的"+"号为什么会丢失,如何保证参数完整
  7. ubuntu下使用mysql的一点笔记
  8. [libgdx游戏开发教程]使用Libgdx进行游戏开发(8)-粒子系统
  9. (九)MySQL用户和权限管理
  10. 【互动问答分享】第8期决胜云计算大数据时代Spark亚太研究院公益大讲堂