【发布时间】:2016-06-19 15:42:52
【问题描述】:
我有一个 UIView 子类,它只包含以下内容:
drawRect(rect: CGRect) {
let ctx: CGContext? = UIGraphicsGetCurrentContext()
let radius: CGFloat = rect.width / 2
let endAngle = CGFloat(2 * M_PI)
CGContextAddArc(ctx, bounds.width / 2, bounds.height / 2, radius, 0, endAngle, 1)
CGContextSetStrokeColorWithColor(ctx, UIColor.blackColor().CGColor)
CGContextSetFillColorWithColor(ctx, UIColor.whiteColor().CGColor)
CGContextSetLineWidth(ctx, 4.0)
CGContextDrawPath(ctx, CGPathDrawingMode.FillStroke)
}
我没有调用任何 init() 函数,但对象仍在绘制中。
此外,当我尝试实现一个 init() 函数时,我收到了几个关于所需初始化的错误。
所以我的问题是:如何在没有 init() 函数的情况下创建 UIView 对象?
【问题讨论】:
标签: ios swift macos uiview core-graphics