我正在尝试子类化UIButton,所以我可以对它们进行自定义动画,但我遇到了初始化问题
属性'self.originalWidth'未在super.init调用中初始化
这是我的代码:
import UIKit
enum ButtonType {
case newGameButton
case showStatsButton
case addTeamButton
case addUserButton
}
class LSS_Button: UIButton {
var myButtonType:ButtonType?
var originalWidth:CGFloat
var originalHeight:CGFloat
required init?(coder aDecoder: NSCoder) {
fatalError("Something went terribly wrong with init on LSS_Button")
}
override init(frame: CGRect) {
super.init(frame: frame)
self.originalWidth = self.frame.size.width
self.originalHeight = self.frame.size.height
}
我该如何解决这个问题?提前谢谢。
忘记添加,如果我把self.originalWidth = ...放在super.init上面,那么我得到这个错误:
在super.init call之前使用'self'
答案 0 :(得分:0)
override init(frame: CGRect) {
self.originalWidth = frame.size.width
self.originalHeight = frame.size.height
super.init(frame: frame)
}