У Баттона все хорошо, но ударить невозможно - PullRequest
0 голосов
/ 08 апреля 2019

При нажатии кнопки UIB пара кнопок ударит и нажмет другую кнопку, удар не будет не затронут, это проблема, функция удара работает нормально и не получает удара ...

код: unstrike

    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))

}

enter image description here

1 Ответ

0 голосов
/ 08 апреля 2019

Установить свойство удара и снятия удара для 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

Примечание: Убедитесь, что тип UIButton должен быть пользовательским.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...