我有一个开关,我想根据某些情况限制切换。 如何根据某些条件限制开关状态变化?我还在DispatchQueue.main.async中尝试了setOn。
if sender.isOn{
self.pmLabel.textColor = UIColor.ktvPurple()
self.amLabel.textColor = UIColor.lightGray
if let pmTime = self.eveningShowtime{
updateClock(from: CGFloat(pmTime), to: CGFloat(pmTime) + CGFloat(durationsHours))
updatePieChart()
}else{
self.view.makeToast("Evening Shows are not available", duration: 1.0, position:CGPoint(x: SCREENWIDTH/2, y: SCREENHEIGHT - 180))
ampmSwitch.isOn = false
}
}else{
self.amLabel.textColor = UIColor.ktvPurple()
self.pmLabel.textColor = UIColor.lightGray
if let morningTime = self.morningShowTime{
updateClock(from: CGFloat(morningTime), to: CGFloat(morningTime) + CGFloat(durationsHours))
updatePieChart()
}else{
self.view.makeToast("Morning Shows are not available", duration: 1.0, position:CGPoint(x: SCREENWIDTH/2, y: SCREENHEIGHT - 180))
ampmSwitch.isOn = true
}
}
答案 0 :(得分:1)
例如:
if yourCondition {
yourSwitch.enabled = false
}
答案 1 :(得分:0)
您可以为开关使用userInteractionEnabled或启用的属性。