【问题标题】:UIView with curved edges (not corner radius)具有弯曲边缘的 UIView(不是角半径)
【发布时间】:2016-01-28 00:45:23
【问题描述】:

我正在尝试塑造一个 UIView,使其底部边缘曲线向内,如图所示。

我试图用一些简单的东西来完成它,比如负值的圆角半径,但显然这不起作用。似乎需要使用贝塞尔曲线?完成这项工作的最简单方法是什么?

【问题讨论】:

    标签: ios objective-c xcode uiview


    【解决方案1】:
    // To draw an arc path
    
    func drawCircle(view: UIView, startingAngle: CGFloat, endAngle: CGFloat) -> CAShapeLayer {
        let path = UIBezierPath(arcCenter: CGPoint(x:arcViewOutlet.frame.size.width/2,y:400), radius: CGFloat((400)), startAngle: startingAngle, endAngle:endAngle, clockwise: true)
    
        let shapeLayer = CAShapeLayer()
        shapeLayer.path = path.cgPath
    
        shapeLayer.strokeColor = UIColor.clear.cgColor
        shapeLayer.fillColor = UIColor.white.cgColor
        shapeLayer.lineCap = kCALineCapRound
    
        view.layer.addSublayer(shapeLayer)
    
        return shapeLayer
    }
    

    根据我的要求,我使用半径为 400。

    如下给出 arcCentres。

    CGPoint(x:arcViewOutlet.frame.size.width/2,y:400) //for top edge curve 
    CGPoint(x:arcViewOutlet.frame.size.width/2,y:-400) //for bottom edge curve 
    CGPoint(x:400,y:arcViewOutlet.frame.size.height/2) //for left edge curve 
    CGPoint(x:-400,y:arcViewOutlet.frame.size.height/2) //for right edge curve
    

    【讨论】:

      【解决方案2】:

      您可以使用CAShapeLayer 作为UIView 的子层或支持层。 CAShapeLayer 允许您设置路径、描边、填充等。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-25
        • 2022-08-03
        相关资源
        最近更新 更多