Reputation: 1221
This is my code
func drawSmallCircles(){
for oneArray in points {
let startAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[0]))
let endAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[1]))
let radius: CGFloat = 100.0
let path = UIBezierPath(arcCenter: center,
radius: radius,
startAngle: startAngleRadiant,
endAngle: endAngleRadiant,
clockwise: true)
let color = UIColor(red: CGFloat(55), green: CGFloat(37), blue: CGFloat(23), alpha: CGFloat(1))
path.fill()
color.setFill()
path.lineWidth = CGFloat(10)
path.stroke()
setNeedsDisplay()
}
}
as you see, i am having a custom color. my problem is that the color always black.
see
override func drawRect(rect: CGRect) {
self.opaque = false;
drawSmallCircles()
}
this is the drawRec for me
after Rob answer, this is my code
let points = [[270, 290],[300, 320],[330, 350],[0, 20],[30, 50],[60, 80],[90, 110],[120, 140],[150, 170],[180, 200],[210, 230],[240, 260]]
func drawSmallCircles(){
for oneArray in points {
let startAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[0]))
let endAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[1]))
let radius: CGFloat = 50.0
let path = UIBezierPath(arcCenter: CGPoint(x: CGFloat(100), y: CGFloat(100)),
radius: radius,
startAngle: startAngleRadiant,
endAngle: endAngleRadiant,
clockwise: true)
let color = UIColor(red: CGFloat(55/255), green: CGFloat(37/255), blue: CGFloat(23/255), alpha: CGFloat(1))
// path.fill()
color.setStroke()
path.lineWidth = CGFloat(10)
path.stroke()
// setNeedsDisplay()
}
}
override func drawRect(rect: CGRect) {
self.opaque = false;
drawSmallCircles()
}
but still the same black color,
i did what you said and i called the setStock method on the color and i changed the colors values to 0 between 255
Upvotes: 1
Views: 1623
Reputation: 437532
If you refer to the documentation for initWithRed:green:blue:alpha:
, it points out that those should be values between 0.0
and 1.0
.
Furthermore, you never call setStroke
to set the line color. You call color.setStroke()
to set the color, and then call path.stroke()
to draw the stroke at the previously specified color.
--
You might want something like:
func drawSmallCircles(){
for oneArray in points {
let startAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[0]))
let endAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[1]))
let radius: CGFloat = 100.0
let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: startAngleRadiant, endAngle: endAngleRadiant, clockwise: true)
let color = UIColor(red: 55.0/255.0, green: 37.0/255.0, blue: 23.0/255.0, alpha: 1.0)
color.setStroke()
path.lineWidth = CGFloat(10)
path.stroke()
}
}
Note, that's a pretty dark color, so it might look black. You might want to lighten that up (using a few values closer to 1.0
) to see the color more clearly.
Upvotes: 1