首页 > 解决方案 > Swift 左侧只有带边框的圆形按钮

问题描述

我怎样才能得到这种下拉菜单?

我正在使用按钮。能够得到圆角,但左边的边界是圆的,右边是直的是一个问题

标签: iosswiftuibutton

解决方案


您可以按照以下步骤来实现您想要的 Dropdown 布局。

1.使用 UITableView 进行下拉。

2.创建一个UITableViewCell。

3.向一侧的UIView添加圆角。

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

 self.roundedView.layer.backgroundColor = UIColor.purple.cgColor
//Here I'm masking the textView's layer with rectShape layer
 self.roundedView.layer.mask = rectShape

4.给roundedView添加边框。


推荐阅读