我有一个自定义选择器 View ,它工作得很好,但有一个问题。您可以再次单击该按钮,然后选择器 View 将被关闭。但是,当它关闭时,取消按钮中的文本将变为空白并且不会保持不变(“选择”是一个打开选择器 View 的按钮,当您从选择器 View 中选择某些内容以反射(reflect)您选择的内容时,其文本会发生变化。我什么想要发生的情况是,如果您再次单击选择按钮(而不是选择器 View ),那么取消按钮中的文本将不会更改并变为空白。
var pickValue:AnyObject? {
didSet{
if let pickValue = pickValue{
Select.setTitle("\(pickValue)", for: UIControlState())
}else{
Select.setTitle("Select", for: UIControlState())
}
}
}
@IBAction func Show(_ sender: AnyObject) {
let pickercontrol = LCTableViewPickerControl(
frame: CGRect(x: 0, y: self.view!.frame.size.height + 150, width: view.bounds.size.width - 50, height: 150),
title: "Please pick an item",
value: pickValue,
items: ["minute", "hour", "day", "month", "year"],
offset: CGPoint(x: 0, y: 0))
pickercontrol?.tag = 1
view.addSubview(pickercontrol!)
pickercontrol?.show(in: view) { [weak self](sender, item) in
guard let view = sender as? LCTableViewPickerControl else{
return
}
view.dismiss()
self?.pickValue = item as AnyObject?
}
}
The image when the picker view is initialized and your able to pick a value
最佳答案
您需要设置您想要的 controlState。 对于 UIControlState.normal
关于ios - Swift 3.0 字符串问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39925882/