I have the following code in my Draw2D class which is attached to the view in the viewcontroller.
In the viewcontroller I have a var Drawing = Draw2D(). I have a button hooked up which performs the function "Check" with self.Drawing.Check(). The problem is I can't get the line on the screen. The ellipse works fine and function Check performs well as I can see with println().
What is wrong?
import UIKit
class Draw2D: UIView {
override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 4.0)
CGContextSetStrokeColorWithColor(context, UIColor.blueColor().CGColor)
let rectangle = CGRectMake(60,170,200,80)
CGContextAddEllipseInRect(context, rectangle)
CGContextStrokePath(context)
}
func Check() {
let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 2.0)
CGContextMoveToPoint(context, CGFloat(100), CGFloat(300))
CGContextAddLineToPoint(context, CGFloat(100 + 200), CGFloat(300 + 100))
CGContextStrokePath(context)
}
}
Check()called?drawRectwhich is call by the system. You need to change thedrawRectto handle drawing the check.