Я создаю подкласс UIButton, чтобы добавить рисунок. Он отлично работает в коде. Это дает следующую ошибку, когда я пытаюсь использовать @IBdesignable.
ошибка: IB Designables: не удалось обновить статус автоматического макета: произошел сбой агента
ошибка: IB Designables: не удалось отобразить экземпляр DashboardHeaderView: произошел сбой агента
Ниже приведен пример кода
let context:CGContextRef = UIGraphicsGetCurrentContext()!
UIGraphicsPushContext(context)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0);
var path:UIBezierPath!
let pathRect:CGRect = CGRectMake(strokeWidth / 2, strokeWidth / 2, pathSize - iconStrokeWidth, pathSize - iconStrokeWidth);
path = UIBezierPath(rect: pathRect )
iconColor.setStroke()
iconPath.lineWidth = iconStrokeWidth;
iconPath.stroke()
CGContextAddPath(context, iconPath.CGPath);
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsPopContext();
UIGraphicsEndImageContext();
Ошибка сбоя агента
let context:CGContextRef = UIGraphicsGetCurrentContext()!
Я отключил init + drawRect + initilizeButtonDrawings, но ничего положительного не получил
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
self.initilizeButtonDrawings()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.initilizeButtonDrawings()
}
override func drawRect(rect:CGRect) {
super.drawRect(rect)
self.initilizeButtonDrawings()
}
override func prepareForInterfaceBuilder () {
self.initilizeButtonDrawings()
}
Все это отлично работает с Objective C, но падает в swift.