При нажатии кнопки UIButton будет нажата пара кнопок, а при нажатии другой кнопки забастовка не будет отменена, это проблема, функция забастовки работает нормально, а забастовка не получается....
код: снять удар
func updAvaTime() {
upAvailableTime(sender:time805Btn)
upAvailableTime(sender:time830Btn)
upAvailableTime(sender:time905Btn)
upAvailableTime(sender:time930Btn)
upAvailableTime(sender:time1005Btn)
upAvailableTime(sender:time1030Btn)
upAvailableTime(sender:time115Btn)
upAvailableTime(sender:time1130Btn)
upAvailableTime(sender:time125Btn)
upAvailableTime(sender:time1230Btn)
upAvailableTime(sender:time105Btn)
upAvailableTime(sender:time130Btn)
upAvailableTime(sender:time205Btn)
upAvailableTime(sender:time230Btn)
upAvailableTime(sender:time305Btn)
upAvailableTime(sender:time330Btn)
upAvailableTime(sender:time405Btn)
upAvailableTime(sender:time430Btn)
upAvailableTime(sender:time505Btn)
upAvailableTime(sender:time530Btn)
upAvailableTime(sender:time605Btn)
upAvailableTime(sender:time630Btn)
upAvailableTime(sender:time705Btn)
upAvailableTime(sender:time730Btn)
}
func upAvailableTime(sender: UIButton) {
let currentTime = sender.currentTitle//(for: .normal)!
let attrString: NSMutableAttributedString = NSMutableAttributedString(string: currentTime!)
attrString.removeAttribute(NSAttributedString.Key.strikethroughStyle , range:NSMakeRange(0, attrString.length))
}
Было бы полезно, если бы вы могли обновить вопрос с кодами из комментариев выше.
Установить свойство strike и unstrike для UIButton
let attributesUnstrike = [NSAttributedString.Key.strikethroughStyle : 0]
let titleUnselected = NSAttributedString(string: "YOUR STRING", attributes: attributesUnstrike)
//Set strike for selected state
let attributesStrike = [NSAttributedString.Key.strikethroughStyle : 1]
let titleSelected = NSAttributedString(string: "YOUR STRING", attributes: attributesStrike)
btn.setAttributedTitle(titleUnselected, for: .normal)
btn.setAttributedTitle(titleSelected, for: .selected)
@IBAction func reloadtable(sender:UIButton){
sender.isSelected = !sender.isSelected
//Automatically change Button state automatically based on curent state
}
Обновлять:
time805Btn.isSelected = true // To Strike
time805Btn.isSelected = false // To Unstrike
Note: Make sure your
UIButton
type should be custom.
пусть currentTime = sender.currentAttributedTitle?.mutableCopy() как! NSMutableAttributedString, получение (Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0))
Мэм, это просто код для удара/снятия UIButton. Вы должны реализовать свою логику в соответствии с вашими требованиями.
как ты добавил зачеркивание в свою кнопку