मैं देख रहा हूँ कुछ अजीब व्यवहार की एक सरणी से बटन मैं में बनाया गया है, स्टोरीबोर्ड. मैं 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)
}
}