2016-04-15 37 views
0

UIBezierPathで傾斜した楕円を描画したいと思います。 slopを使わずに楕円を描く方法はUIBezierPath.init(ovalInRect: rect)しかありません。私はこれを描くために何ができますか?おかげでここUIBezierPathで傾斜した楕円を描く方法

+0

私は私が最初に傾斜した長方形を得ることができることを推測します、私はこの斜めの長方形で楕円を描画することができます –

+0

これは役に立つかもしれませんhttp://stackoverflow.com/questions/10643928/draw-ellipse-with-start-and-end-angle-in-objective-c –

+2

傾斜した楕円形はどういう意味ですか?画像を投稿してもよろしいですか? –

答えて

4

は、回転楕円形の例である:

class MyView: UIView { 
    override func draw(_ rect: CGRect) { 
     // create oval centered at (0, 0) 
     let path = UIBezierPath(ovalIn: CGRect(x: -75, y: -50, width: 150, height: 100)) 

     // rotate it 30 degrees 
     path.apply(CGAffineTransform(rotationAngle: 30 * .pi/180)) 

     // translate it to where you want it 
     path.apply(CGAffineTransform(translationX: self.bounds.width/2, y: self.bounds.height/2)) 

     // set stroke color 
     UIColor.blue.setStroke() 

     // stroke the path 
     path.stroke() 
    } 
} 

let view = MyView(frame: CGRect(x: 0, y: 0, width: 200, height: 200)) 
view.backgroundColor = .white 

ここでは、プレイグラウンドで実行されている:

enter image description here

+0

nice。本当にありがとう –

関連する問題