我有一個默認的UIButton鏈接到IBAction(觸摸裏面)。這工作正常,所以我知道我的連接是好的。一旦我將UIButton類更改爲自定義按鈕,IBAction不再被觸發。以下是我的自定義UIButton的代碼。任何想法爲什麼發生這種情況?自定義UIButton - IBAction不工作
import UIKit
@IBDesignable
class PrimaryButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
initView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initView()
}
private func initView() {
let view = viewFromNibForClass()
view.frame = bounds
view.autoresizingMask = [
UIViewAutoresizing.flexibleWidth,
UIViewAutoresizing.flexibleHeight
]
addSubview(view)
}
private func viewFromNibForClass() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
return view
}
}