2015-10-28 123 views
1

我試圖用其底部邊緣曲線向內塑造UIView,如圖中所示。具有彎曲邊緣的UIView(而不是圓角半徑)

enter image description here

我試圖用一些簡單的像與負值的圓角半徑來完成它,但很明顯,這是行不通的。似乎需要使用貝塞爾曲線?什麼是最簡單的方法來完成這件事?

回答

0

您可以使用CAShapeLayer作爲UIView的子層或背層。 CAShapeLayer允許您設置的路徑,描邊,填色等

+0

謝謝@FelixLam指引我正確的方向。 :) – john7ric

0
// 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