我想按照这个圆标签和按钮的三个角: rounded button拐角不是圆形的UILabel和UIButton的IOS迅速
但结果是:
一些角落的标签是四舍五入的,有些不是。类似的,它发生的按钮和宽度超过了按钮走出tableview。
这是我使用的扩展代码:
extension UIButton{
func roundedButton(){
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topLeft, .bottomLeft, .bottomRight],
cornerRadii:CGSize(width:8,height:8))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.masksToBounds=true
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
}
}
extension UILabel{
func roundedLabel(){
let maskPAth1 = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: [.topRight,.bottomRight,.bottomLeft],
cornerRadii:CGSize(width:10,height:10))
let maskLayer1 = CAShapeLayer()
maskLayer1.frame = self.bounds
maskLayer1.cornerRadius=5
maskLayer1.masksToBounds=true
maskLayer1.path = maskPAth1.cgPath
self.layer.mask = maskLayer1
}
}
我打电话
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {}
在iOS中制作圆角很容易。所有你需要的是'view.layer.cornerRadius = aFloat'。没有必要继承任何东西,它适用于'UIView'的所有子类' –
[在Rift中使用UIRectCorner的圆角矩形不能正常工作]的可能的重复(https://stackoverflow.com/questions/33050585/rounded-rect-using-u- directcorner在迅速不工作) –