我在我的Draw2D类中附加了视图控制器中的视图中的以下代码。在Swift中调用Draw函数
在视图控制器中,我有一个var Drawing = Draw2D()
。我有一个按钮连接到self.Drawing.Check()
执行功能“检查”。问题是我无法获得屏幕上的线。椭圆工作正常,功能检查表现良好,我可以看到println()
。 有什么不对?
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)
}
}
哪里是'检查()'叫什么名字? – luk2302
这是的ViewController – user2761551
'变种绘图= Draw2D的() @IBAction FUNC Button1的(发送者:AnyObject) { self.Drawing.Check() }' – user2761551