2017-06-12 5 views
1

How to curve the top of a UIView Controller in Swiftswift3を使用してUIViewの上部をカーブする方法は?

私はそれを見ました。これは、以下に添付ます。私は私の視点から背中の色を取り除きたい。私はストーリーボードでuiviewを作り、そのビューにカスタムクラスを割り当てました。

want to remove the black color

私のカスタムクラスは、まあ、単にそれのCustomViewへのbackgroundColorを与える

class curvedView: UIView { 

override func draw(_ rect: CGRect) { 

    let color = UIColor(rgb: 0x285387) 
    let y:CGFloat = 0 
    // let curveTo:CGFloat = 50 

    let myBezier = UIBezierPath() 
    myBezier.move(to: CGPoint(x: 0, y: y)) 

    myBezier.addQuadCurve(to: CGPoint(x: rect.width, y: y), controlPoint: CGPoint(x: rect.width/2, y: rect.height/3)) 
    myBezier.addLine(to: CGPoint(x: rect.width, y: rect.height)) 
    myBezier.addLine(to: CGPoint(x: 0, y: rect.height)) 
    myBezier.close() 
    let context = UIGraphicsGetCurrentContext() 
    context!.setLineWidth(2.0) 

    color.setFill() 
    myBezier.fill() 
}} 

extension UIColor { 
convenience init(red: Int, green: Int, blue: Int) { 
    assert(red >= 0 && red <= 255, "Invalid red component") 
    assert(green >= 0 && green <= 255, "Invalid green component") 
    assert(blue >= 0 && blue <= 255, "Invalid blue component") 

    self.init(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: 1.0) 
} 

convenience init(rgb: Int) { 
    self.init(
     red: (rgb >> 16) & 0x28, 
     green: (rgb >> 8) & 0x53, 
     blue: rgb & 0x87 
    ) 
}} 

答えて

2

です。

同様:

class curvedView: UIView { 

    override func layoutSubviews() { 
     self.backgroundColor = .clear 
    } 

    override func draw(_ rect: CGRect) { 
     let color = UIColor(rgb: 0x285387) 
     let y:CGFloat = 0 
     let myBezier = UIBezierPath() 
     myBezier.move(to: CGPoint(x: 0, y: y)) 
     myBezier.addQuadCurve(to: CGPoint(x: rect.width, y: y), controlPoint: CGPoint(x: rect.width/2, y: rect.height/3)) 
     myBezier.addLine(to: CGPoint(x: rect.width, y: rect.height)) 
     myBezier.addLine(to: CGPoint(x: 0, y: rect.height)) 
     myBezier.close() 
     color.setFill() 
     myBezier.fill() 
    } 
} 

または代わりにその優れた初期のそれを与えるために:

class curvedView: UIView { 

    override func draw(_ rect: CGRect) { 
     let color = UIColor(rgb: 0x285387) 
     let y:CGFloat = 0 
     let myBezier = UIBezierPath() 
     myBezier.move(to: CGPoint(x: 0, y: y)) 
     myBezier.addQuadCurve(to: CGPoint(x: rect.width, y: y), controlPoint: CGPoint(x: rect.width/2, y: rect.height/3)) 
     myBezier.addLine(to: CGPoint(x: rect.width, y: rect.height)) 
     myBezier.addLine(to: CGPoint(x: 0, y: rect.height)) 
     myBezier.close() 
     color.setFill() 
     myBezier.fill() 

    } 
    override init(frame: CGRect) { 
     super.init(frame: frame) 
     self.backgroundColor = UIColor.clear 
    } 

    required init?(coder aDecoder: NSCoder) { 
     super.init(coder: aDecoder) 
     self.backgroundColor = UIColor.clear 

    } 
} 
+0

は...その...働い –

+0

トイレ、ありがとうございました。それがあなたを助けたら投票してください。 – ankit

関連する問題