It is inadvisable to store the context pointer across calls to drawRect
. Each call to drawRect
should make its own call to UIGraphicsGetCurrentContext()
to get the context pointer. From there, pass it where it needs to go. You could do the following:
def drawRect(rect)
context = UIGraphicsGetCurrentContext()
setBackgroundRed(context)
# call more private methods to draw other stuff here
end
private
def setBackgroundRed(context)
CGContextSetFillColorWithColor(context, redColor)
CGContextFillRect(context, bounds)
end
def redColor
UIColor.colorWithRed(1.0, green: 0.0, blue: 0.0, alpha:1.0).CGColor
end