Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在雨燕光滑圆角_Ios_Swift_Rounded Corners - Fatal编程技术网

Ios 在雨燕光滑圆角

Ios 在雨燕光滑圆角,ios,swift,rounded-corners,Ios,Swift,Rounded Corners,如何创建圆角平滑的UIButton? 标准苹果圆角比标准圆角好得多。 如果我在草图中设计一个按钮,我可以切换“平滑角”,将形状的角从苹果圆角(平滑)切换到标准圆角 以下是一个比较: 如何在swift中切换此选项 showContentButton.layer.cornerRadius=20圆角,但是,我不知道这个圆角是“平滑圆角”还是“标准圆角”。我不知道如何切换这个。有什么想法吗?在iOS 13之前 要获得这种效果,您可以使用UIBezierPath 编辑: UIView中的用法 clas

如何创建圆角平滑的UIButton? 标准苹果圆角比标准圆角好得多。 如果我在草图中设计一个按钮,我可以切换“平滑角”,将形状的角从苹果圆角(平滑)切换到标准圆角

以下是一个比较:

如何在swift中切换此选项


showContentButton.layer.cornerRadius=20
圆角,但是,我不知道这个圆角是“平滑圆角”还是“标准圆角”。我不知道如何切换这个。有什么想法吗?

在iOS 13之前

要获得这种效果,您可以使用
UIBezierPath

编辑: UIView中的用法

class MyView: UIView {

    let myButton UIButton = UIButton()

    override func layoutSubviews() {
        super.layoutSubviews()

        // your roundPath code here
    }

}
编辑2:

使用此方法对特定拐角进行圆角处理:

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

只需使用此扩展名

extension CALayer {

   func roundCorners(radius: CGFloat) {
       let roundPath = UIBezierPath(
           roundedRect: self.bounds,
           cornerRadius: radius)
       let maskLayer = CAShapeLayer()
       maskLayer.path = roundPath.cgPath
       self.mask = maskLayer
   }

}
像这样使用它

cell.layer.roundCorners(radius: 18)

从iOS 13.0开始,除了设置拐角半径外,您还可以使用此属性:

sampleButton.layer.cornerCurve = .continuous
这也很容易设置动画,以前使用UIBezierPath会导致问题


详见

按钮完全消失。我做了:
让SmoothCornerRoundedPath=UIBezierPath(roundedRect:bounds,cornerRadius:8)让maskLayer=CAShapeLayer()maskLayer.path=SmoothCornerRoundedPath.cPath=showContentButton.layer.mask=maskLayer
你是在
布局子视图
方法中做的吗?按钮只有一个圆角。但这似乎是一个平滑的角落。但所有其他三个角都是锐角(90°)最后一个问题:如何将角半径限制为特定的角?例如:右上角和右下角应该是圆角,但左上角和左下角应该是尖锐的。@WalterBeiter谢谢!我有一个备忘录,我的解决方案在iOS 13之前。