不同的cornerRadius为每个角落Swift 3 - iOS [英] Different cornerRadius for each corner Swift 3 - iOS

查看:311
本文介绍了不同的cornerRadius为每个角落Swift 3 - iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为Swift -3中的视图设置不同的角半径,我可以将每个角的半径设置为相同的值,如下面的帖子中提到的那样,如何设置cornerRadius仅用于左上角和UIView的右上角?

I want to set different corner radius for a view in Swift -3 , I am able to set the radius for the each corner to the same value like the one mentioned in the following post ,how to set cornerRadius for only top-left and top-right corner of a UIView?

有没有办法可以按以下格式设置转角半径?
半径左上:18
半径右上:18
半径右下:3
半径左下:18

Is there a way I can set the corner radius in the following format ? Radius top-left: 18 Radius top-right: 18 Radius bottom-right: 3 Radius bottom-left: 18

推荐答案

您可以将默认的 layer.cornerRadius 设置为最小值,然后将图层蒙版的边框设置为更大值。

You could set the default layer.cornerRadius to the smallest value and then set the layer mask's border to the bigger value.

let demoView = UIView(frame: CGRect(x: 100, y: 200, width: 100, height: 100))
demoView.backgroundColor = UIColor.red
demoView.layer.cornerRadius = 3.0

let maskPath = UIBezierPath(roundedRect: demoView.bounds,
                            byRoundingCorners: [.topLeft, .topRight, .bottomLeft],
                            cornerRadii: CGSize(width: 18.0, height: 0.0))

let maskLayer = CAShapeLayer()
maskLayer.path = maskPath.cgPath
demoView.layer.mask = maskLayer
view.addSubview(demoView)

这篇关于不同的cornerRadius为每个角落Swift 3 - iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆