swift3 细节改动 竖线|与语法的改动

主要说一下竖线与语法的改动
下面的例子都是添加圆角的方法

在OC中:

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;
UIRectCornerBottomLeft|UIRectCornerBottomRight 意思是在view2的左下角和右下角设置圆角

在Swift3.0以前:

 var rect =CGRect(x:0, y:0, width:200, height:40)
var textfield = UITextField(frame: rect)
textfield.backgroundColor=UIColor.lightGrayColor()// 背景颜色
textfield.text="GAGA"
textfield.textAlignment= NSTextAlignment.Center
textfield.textColor=UIColor.darkGrayColor()
var maskPath = UIBezierPath(roundedRect: textfield.bounds,    byRoundingCorners: UIRectCorner.TopLeft| UIRectCorner.TopRight,// 左上右上圆角
    cornerRadii:CGSize(width:12, height:12))// 圆角半径

/* 边框  */
var borderLayer = CAShapeLayer()
borderLayer.frame= textfield.bounds
borderLayer.path= maskPath.CGPath
borderLayer.strokeColor=UIColor.darkGrayColor().CGColor// 边框颜色borderLayer.fillColor=UIColor.clearColor().CGColor

/* 遮罩 */

var maskLayer = CAShapeLayer()
maskLayer.frame= textfield.bounds
maskLayer.path= maskPath.CGPath
textfield.layer.mask= maskLayer
textfield.layer.addSublayer(borderLayer)

可以看出UIRectCorner.TopLeft| UIRectCorner.TopRight和OC写法还是一样的,在textfield的左上和右上添加圆角

Swift3.0 :

let maskPath = UIBezierPath(roundedRect: (cell?.bounds)!, byRoundingCorners: [.topLeft, .topRight], cornerRadii:CGSize(width:10, height:10))

let masklayer =CAShapeLayer()
masklayer.frame= (cell?.bounds)!
masklayer.path= maskPath.cgPath
cell?.layer.mask= masklayer

这个方法里面[.topLeft, .topRight]也是表示与语法,在cell的左上和右上添加圆角,而且在Swift3.0
上面的写法都会报错,这应该也算去C写法,一个数组里面有两个选项添加在圆角类型上,而且这也更符合byRoundingCorners这个复数s。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 因为要结局swift3.0中引用snapKit的问题,看到一篇介绍Xcode8,swift3变化的文章,觉得很详细...
    uniapp阅读 4,911评论 0 12
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 16,584评论 4 61
  • 1. 我还记得,我第一次和詹姆斯·詹姆斯碰面时,那是个秋天的下午。 那天我心情忧郁,又闲得无聊,于是一个人去逛一个...
    火烧风阅读 579评论 0 0
  • 上一章 婚礼开始,新娘站在花环拱门处,圣洁的婚纱下是新娘娇羞的脸,人生最幸福的该是这一刻了吧,以最美的姿态,嫁给自...
    梧桐兮兮阅读 380评论 0 1

友情链接更多精彩内容