0
UIBezierPathセクションごとに異なるストロークカラーを設定したいとします。しかし、命令は完全に間違っており、私はそれを修正する方法を知らない。UIGraphicsGetCurrentContextごとに異なるsetStrokeカラー
そして、これは私が得るものです::
これは私が欲しいものである
順序が間違っているように思えます。 bezierPathに色をバインドしてコンテキストに追加する方法はありますか?私のコードは以下の通りです。ありがとう!
let size = CGSize(width: 134, height:51)
UIGraphicsBeginImageContext(size)
let context = UIGraphicsGetCurrentContext()
//// Rectangle Drawing
let rectanglePath = UIBezierPath(roundedRect: CGRect(x: 0.5, y: 0.5, width: 126, height: 50), cornerRadius: 3)
UIColor.lightGray.setStroke()
rectanglePath.lineWidth = 1
rectanglePath.stroke()
let clipPath: CGPath = rectanglePath.cgPath
context?.addPath(clipPath)
//// Rectangle 2 Drawing
let rectangle2Path = UIBezierPath(roundedRect: CGRect(x: 3, y: 3, width: 121, height: 45), cornerRadius: 3)
UIColor.green.setFill()
rectangle2Path.fill()
let clipPathh: CGPath = rectangle2Path.cgPath
context?.addPath(clipPathh)
let rectangle3Path = UIBezierPath(roundedRect: CGRect(x: 128, y: 18, width: 6, height: 14), byRoundingCorners: [.topRight, .bottomRight], cornerRadii: CGSize(width: 3, height: 3))
UIColor.gray.setFill()
rectangle3Path.fill()
let clipPathhh: CGPath = rectangle3Path.cgPath
context?.addPath(clipPathhh)
context?.closePath()
// Convert to UIImage
let cgimage = context!.makeImage();
let uiimage = UIImage(cgImage: cgimage!)
// End the graphics context
UIGraphicsEndImageContext()
image.image = uiimage;
私はIBを使って投げ込まれたUIImageViewを使って、あなたのコードを新しいプロジェクトにコピーして貼り付けました。私は正しい結果を得ています。緑色の塗りつぶしを囲む明るい灰色の境界なぜそれが私のために働くかわからない。あなたが本当に望むのは、白い枠線の外に灰色の枠線があり、緑色の枠線がある場合は、白の第3の経路が必要な場合があります。 – dfd
Mhh、それをviewDidLoadに貼り付けましたか? – da1lbi3
はい。再び、粗くて素早いコピー/過去。ベジェパスの場合は、通常、ビューのdrawRect内のものが必要です。 – dfd