ฉันเห็นบางอย่างแปลกๆพฤติกรรมจากอาเรย์ของปุ่มฉันต้องสร้างใน storyboard. ผมมี 4 ปุ่มแต่ละชนิดตั้งเอง TakesContainerButton
และตอนที่ปุ่มคือมีการคลิกมันจะเปลี่ยนกับระบบแบบอักษรแต่พอที่แตกต่างกันปุ่มคือมีการคลิกที่ความเดิมตอนที่แล้วปุ่มกลับมาเพื่อที่ต้องการแบบอักษร,ไม่แน่ใจว่าเกิดอะไรขึ้นที่นี่
ระดุมยังฝังอยู่ในกองเข็องมุมมองถ้ามันสำคัญ
นี่คือที่ implementation ตอนหนึ่งของปุ่มก็ได้กดดันอยู่ไหน 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)
}
}