本文主要是介绍iOS 给控件加圆角,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
这里以UIButton控件为例子,真接上代码了!
UIButton *helpBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
方法一:helpBtn.layer.cornerRadius =5.0; //圆角半径为5.0
helpBtn.layer.masksToBounds =YES;
这样写会将helpBtn的四个角都加上圆角,可不可以只将指定的边角设置为圆角呢?可以 !
方法二:
UIBezierPath *maskPath = [UIBezierPathbezierPathWithRoundedRect:helpBtn.boundsbyRoundingCorners:
UIRectCornerTopLeft |UIRectCornerTopRight
cornerRadii :CGSizeMake ( 4.0f , 4.0f )];CAShapeLayer *maskLayer = [[CAShapeLayeralloc]init];
maskLayer.frame = helpBtn.bounds;
maskLayer.path = maskPath.CGPath;
helpBtn.layer.mask = maskLayer;
以上代码是将helpBtn的左上和右上的边角设置为半径为4.0的圆角。
UIRectCorner有以下四种属性:
UIRectCornerTopLeft //左上
UIRectCornerTopRight //右上
UIRectCornerBottomLeft //左下
UIRectCornerBottomRight //右下
UIRectCornerAllCorners //四个边角
希望对你有帮助!
这篇关于iOS 给控件加圆角的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!