我看到一些怪异的行为从一系列的按钮,我已经建立在故事情节。 我有4个按钮的每一个定义的类型 TakesContainerButton
当一个按钮被点击,它改变系统的字体,但是当一个不同的点击按钮之前按钮返回所需的字体,不知道是什么会在这里
按钮也是嵌在一堆图,如果该事项
这里是执行时其中一个按钮被按下那里 buttons
是一系列的4个按钮
@IBAction func filterPressed(_ sender: TakesContainerButton) {
for button in buttons {
button.unclick()
}
sender.click()
}
这里是定义类
class TakesContainerButton: UIButton {
var bottom = UIView()
func click(){
self.setTitleColor(.darkGray, for: .normal)
let xOffset:CGFloat = 10
bottom = UIView(frame: CGRect(x: xOffset / 2, y: self.frame.height - 3, width: self.frame.width - xOffset, height: 3))
bottom.layer.cornerRadius = 1.5
bottom.backgroundColor = .darkGray
self.addSubview(bottom)
}
func unclick(){
bottom.removeFromSuperview()
self.setTitleColor(UIColor(hex: "8B8B8B"), for: .normal)
}
override func awakeFromNib(){
setFont()
}
func setFont(){
self.titleLabel?.font = UIFont(name: "Lato-Bold", size: 12)
}
}