Viewの上に円を描写しているのですが、塗りつぶしか枠線の描写どちらか一方しかできません(塗りつぶし優先)、同時に描写する方法を御存知でしたら教えて下さい。
swift
1 2class TestView: UIView { 3 4 override func awakeFromNib() { 5 super.awakeFromNib() 6 7 layer.cornerRadius = 5.0 8 clipsToBounds = true 9 } 10 11 override func draw(_ rect: CGRect) { 12 super.draw(rect) 13 14 let ctx: CGContext? = UIGraphicsGetCurrentContext() 15 16 let circleSize: CGFloat = self.bounds.size.width / 2 17 let center = CGPoint(x: self.frame.width / 2, y: self.frame.height / 2) 18 19 let lineWidth: CGFloat = 4.0 20 let lineColor: UIColor = UIColor.white 21 let fillColor: UIColor = UIColor.green 22 23 ctx?.setLineWidth(lineWidth) 24 ctx?.setStrokeColor(lineColor.cgColor) 25 ctx?.setFillColor(fillColor.cgColor) 26 27 ctx?.addArc(center: center, radius: circleSize * 0.5, startAngle: 0.0, endAngle: CGFloat(.pi * 2.0), clockwise: false) 28 29 ctx?.setLineWidth(lineWidth) 30 31 ctx?.fillPath() 32 ctx?.strokePath() 33 } 34}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/01/09 04:27