使用相关的知识点是CALayer, 对这些内容一知半解的。

开发中用到了,搜索了很多网页,也算是做个小总结。

一直接设置View的四个角为圆角。

#import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = cornerRadiusInPixels;
view.layer.masksToBounds = YES;

直接在使用的组建View上设置。

二 根据需要设置View的角,比如左上,左下,右上,右下

往上搜索的相关方法是,制作一个相关的图片,然后覆盖上。

此方法来自:http://stackoverflow.com/questions/4847163/round-two-corners-in-uiview

static inline UIImage* MTDContextCreateRoundedMask( CGRect rect, CGFloat radius_tl, CGFloat radius_tr, CGFloat radius_bl, CGFloat radius_br ) {  CGContextRef context;CGColorSpaceRef colorSpace;colorSpace = CGColorSpaceCreateDeviceRGB();// create a bitmap graphics context the size of the imagecontext = CGBitmapContextCreate( NULL, rect.size.width, rect.size.height, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast );// free the rgb colorspaceCGColorSpaceRelease(colorSpace);    if ( context == NULL ) {return NULL;}// cerate maskCGFloat minx = CGRectGetMinX( rect ), midx = CGRectGetMidX( rect ), maxx = CGRectGetMaxX( rect );CGFloat miny = CGRectGetMinY( rect ), midy = CGRectGetMidY( rect ), maxy = CGRectGetMaxY( rect );CGContextBeginPath( context );CGContextSetGrayFillColor( context, 1.0, 0.0 );CGContextAddRect( context, rect );CGContextClosePath( context );CGContextDrawPath( context, kCGPathFill );CGContextSetGrayFillColor( context, 1.0, 1.0 );CGContextBeginPath( context );CGContextMoveToPoint( context, minx, midy );CGContextAddArcToPoint( context, minx, miny, midx, miny, radius_bl );CGContextAddArcToPoint( context, maxx, miny, maxx, midy, radius_br );CGContextAddArcToPoint( context, maxx, maxy, midx, maxy, radius_tr );CGContextAddArcToPoint( context, minx, maxy, minx, midy, radius_tl );CGContextClosePath( context );CGContextDrawPath( context, kCGPathFill );// Create CGImageRef of the main view bitmap content, and then// release that bitmap contextCGImageRef bitmapContext = CGBitmapContextCreateImage( context );CGContextRelease( context );// convert the finished resized image to a UIImage UIImage *theImage = [UIImage imageWithCGImage:bitmapContext];// image is retained by the property setting above, so we can // release the originalCGImageRelease(bitmapContext);// return the imagereturn theImage;
}  

然后使用上面的函数,在需要的View上进行设置

    UIImage *mask = MTDContextCreateRoundedMask( self.view.bounds, 50.0, 50.0, 0.0, 0.0 );// Create a new layer that will work as a maskCALayer *layerMask = [CALayer layer];layerMask.frame = self.view.bounds;       // Put the mask image as content of the layerlayerMask.contents = (id)mask.CGImage;       // set the mask layer as mask of the view layerself.view.layer.mask = layerMask;              // Add a backaground color just to check if it worksself.view.backgroundColor = [UIColor redColor];// Add a test view to verify the correct mask clippingUIView *testView = [[UIView alloc] initWithFrame:CGRectMake( 0.0, 0.0, 50.0, 50.0 )];testView.backgroundColor = [UIColor blueColor];[self.view addSubview:testView];

UITableView设置为圆角的时候,用1的方法可以。

但是如果UITableView设置两个角为圆角,两个角为方角的时候,2的方法就有错误出现。

现在只能是给UITableView在加一个背景View,使用2进行设置,然后组合显示。

其他参考

实现圆角的三种方法http://www.xiaweipin.com/archives/98
例子 https://github.com/weipin/RoundedCorner

设置组件为圆角的方法相关推荐

  1. Flutter开发:给image设置圆角的方法

    在Flutter开发过程中,一些基本的实现效果是层出不穷,各种基础性的设置都需要开发者很好的掌握,这样在开发过程中才能快速的开发,提高开发效率和进度.那么本博文分享一个在Flutter开发过程中比较常 ...

  2. ai如何做倒角和圆角_AI怎么将直角矩形设置成圆角-AI将直角矩形设为圆角的方法 - 河东软件园...

    Adobe Illustrator(AI)是Adobe公司旗下专门应用于设计行业的软件,因为AI的操作并不难,所有越来越多的人喜欢使用这款软件进行一些设计作业.某些时候用户在设计作业上面绘制直角矩形, ...

  3. css设置四个圆角,css怎么设置4个圆角?css设置4个圆角方法

    div如何设置css圆角边框?css设置4个圆角方法有哪些?这对于刚刚入门的css新手,比较陌生,那么css怎么设置4个圆角?下面我们来看一下css设置4个圆角方法.[推荐学习:CSS3教程] CSS ...

  4. java 圆角组件_Java圆角和透明的边框

    以下屏幕截图显示了TextBubbleBorder1的测试.我想使矩形外部的组件的角完全透明并显示其下方的任何组件.我找到了一种方法,可以通过Clip在Graphics2D实例上设置a (代表圆角之外 ...

  5. 【Android 应用开发】 自定义组件 宽高适配方法, 手势监听器操作组件, 回调接口维护策略, 绘制方法分析 -- 基于 WheelView 组件分析自定义组件

    博客地址 : http://blog.csdn.net/shulianghan/article/details/41520569 代码下载 : -- GitHub : https://github.c ...

  6. 1QPushButton的使用,QLineEdit的使用,设置组件位置,布局(QHBoxLayout,QGridLayout)

     1.新建一个空Qt项目 2 新建一个新的文件(右击项目à添加新文件) 3 配置pro文件属性 SOURCES += \ main.cpp QT += widgets gui 4 编写main.c ...

  7. 如何在 CSS 中设置组件在浏览器屏幕水平垂直居中

    如何在 CSS 中设置组件在浏览器屏幕水平垂直居中   在 CSS 中设置组件在浏览器屏幕水平垂直居中可分解为两个问题,一是设置组件在其父组件的水平垂直居中,二是让其父组件铺满整个屏幕.   对于让最 ...

  8. Vue2.0中子组件向父组件传递数据的方法,以完整demo演示

    子组件child.vue源码: <template><div class="child"><button @click="sendData& ...

  9. 子组件调用父组件方法_Vuejs组件(一)组件的注册使用方法

    点击上方"蓝字",发现更多精彩.前言 又到了愉快的周末,今天下了一天的雨了,我又日常宅宿舍打游戏.刷剧.听音乐写写代码. 前面的基础语法记录完了,接下记录的Vue的组件 01认识组 ...

最新文章

  1. 【仿去哪儿登录】UITextField输入时检查输入框是否为空
  2. java里remark是什么意思_remark的用法和短语例句是什么意思
  3. 巨杉数据库:金融级数据库是怎样炼成的
  4. JavaScript的键盘事件
  5. PC-lint使用说明
  6. 一起 goroutine 泄漏问题的排查
  7. 有一种小说叫“纯爱”:为“纯爱小说系列写的序言
  8. 路由表,路由,路由规则_路由和路由表简介
  9. java 配置hdfs集群_Hadoop集群搭建-04安装配置HDFS
  10. Redmi K50评测:顶级2K屏加持 无愧全价位焊门员
  11. 人类一败涂地电脑版_【天翼云盘】侠盗猎车手5(GTA5) 终极SVIP整合版,话不多说来波狠的!...
  12. 13.C#的函数练习
  13. linux基础学习之关机命令总结
  14. python读取文件夹下所有文件名_python如何获取当前文件夹下所有文件名详解
  15. 史上最美大型互联网机房综合布线图鉴
  16. webservice 实现与his系统对接_一键放牧,一架管 1000 头牛!以色列牧民用大疆无人机实现自主放牛;中国重汽对接北斗卫星导航系统,车辆定位精度达到厘米级别!...
  17. mysql 导出gtid_mysqldump导出时 --set-gtid-purged=OFF
  18. 【云原生】什么是云原生?如何学习云原生?一篇文章带你了解云原生
  19. JS 的 _.isEmpty()函数使用
  20. 敏捷街上的噩梦2:受控敏捷

热门文章

  1. web.xml 解析
  2. 报告显示:2023年,电信区块链业产值将达10亿美元
  3. AC_AttitudeControl_Heli.cpp的void AC_AttitudeControl_Heli::rate_bf_to_motor_roll_pitch函数代码分析
  4. 视频融合云服务EasyCVR平台iframe视频套嵌出现滚动条是什么原因?
  5. android 联系人 头像
  6. LVS三种工作方式八种算法
  7. limma | 配对样本的差异分析怎么搞!?(一)
  8. xge_mac学习(2) -- 模块结构
  9. 键盘快捷键大全 - Mac 技巧
  10. 低成本、大容量、高交互…Polkadot 引领 GameFi 实现新突破