0
我不知道爲什麼不能找到這個類。我已經看過類似於此的其他帖子,但是我的委託人的命名慣例不應該干擾迅速。我試過了所有我能想到的東西,但我仍然不知道爲什麼SelectButton無法找到。使用未申報的類型
有什麼想法?
import UIKit
import QuartzCore
protocol SelectButtonDelegate {
func willSelectButton(button: SelectButton)
}
class SelectButton: UIButton {
var delegate: SelectButtonDelegate?
let normalColor = UIColor(white: 0, alpha: 0.2)
let selectedColor = UIColor(white: 0, alpha: 0.4)
let recessedColor = UIColor(white: 0, alpha: 0.5)
init(frame: CGRect, title: String) {
super.init(frame: frame)
backgroundColor = normalColor
setTitle(title, forState: .Normal)
setTitleColor(UIColor(white: 1, alpha: 0.2), forState: .Normal)
setTitleColor(UIColor(white: 1, alpha: 0.7), forState: .Selected)
layer.cornerRadius = 3
bk_addEventHandler({ (object) -> Void in
UIView.animateWithDuration(0.1, animations: {() -> Void in
self.backgroundColor = self.recessedColor
})
}, forControlEvents: .TouchDown)
bk_addEventHandler({ (object) -> Void in
UIView.animateWithDuration(0.1, animations: {() -> Void in
self.backgroundColor = self.currentColor()
})
}, forControlEvents: .TouchUpOutside)
bk_addEventHandler({ (object) -> Void in
UIView.animateWithDuration(0.1, animations: {() -> Void in
self.switchState()
self.backgroundColor = self.currentColor()
})
}, forControlEvents: .TouchUpInside)
}
func currentColor() -> UIColor {
if selected == true {
return selectedColor
}
return normalColor
}
func switchState() {
if selected == true {
selected = false
}
else {
if delegate != nil {
delegate!.willSelectButton(self)
}
selected = true
}
}
func deselect() {
selected = false
UIView.animateWithDuration(0.1, animations: {() -> Void in
self.backgroundColor = self.currentColor()
})
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
你是否正確地將它導入到源文件中,說它無法找到? –
這是唯一的錯誤?您顯示的文本實際上是否被編譯?它是你的目標的一部分嗎? – matt
我使用快速,所以我不需要導入任何東西 –