仅将角半径设置为 UIView/UIButton 的特定一侧 [英] Set corner radius to particular side of UIView/UIButton only

查看:34
本文介绍了仅将角半径设置为 UIView/UIButton 的特定一侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的 UI 元素设置圆角半径,如附加快照所示:

我尝试使用 UIBezierPath 设置拐角半径,但没有给出预期的结果.我还在 UIView 中添加了这三个 UIButton 并将角半径设置为容器视图但没有用.

参考

任何帮助表示赞赏.谢谢

解决方案

用这个来给出圆角半径

let Path = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: [UIRectCorner.TopLeft, UIRectCorner.BottomLeft],cornerRadii: CGSizeMake(1.0, 1.0)).CGPath

I want to set corner radius to my UI element as shown in attached snap:

I tried setting corner radius using UIBezierPath but it doesn't give expected result. I also added those three UIButtons in UIView and set corner radius to Container view but no use.

With reference to https://stackoverflow.com/a/31233171/4886069 , Following is the code what I've tried on top and bottom buttons:

let rectShape = CAShapeLayer()
rectShape.bounds = self.scanButton.frame
rectShape.position = self.scanButton.center
rectShape.path = UIBezierPath(roundedRect: self.scanButton.bounds, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
self.scanButton.layer.mask = rectShape

let rectShape1 = CAShapeLayer()
rectShape1.bounds = self.manualButton.frame
rectShape1.position = self.manualButton.center
rectShape.path = UIBezierPath(roundedRect: self.manualButton.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 20, height: 20)).cgPath
self.manualButton.layer.mask = rectShape1

Following is the code what I've tried on container view:

containerView.layer.cornerRadius = 20

following is the output what I got:

Any help appreciated. Thank you

解决方案

Use this for giving Corner radius

let Path = UIBezierPath(roundedRect: button.bounds, byRoundingCorners: [UIRectCorner.TopLeft , UIRectCorner.BottomLeft], cornerRadii: CGSizeMake(1.0, 1.0)).CGPath

这篇关于仅将角半径设置为 UIView/UIButton 的特定一侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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