请不要标记为重复.可用的答案没有回答我的问题.
我使用UIDatePicker作为UITextField的inputView(在UITableViewCell内):
@IBOutlet weak var theTextField: UITextField! func textFieldDidBeginEditing(_ textField: UITextField) { let picker = UIDatePicker() picker.setValue(Colors.CI2,forKeyPath: "textColor") picker.datePickerMode = .date textField.inputView = picker textField.inputView?.backgroundColor = Colors.CI1 // my desired color picker.addTarget(self,action: #selector(datePickerValueChanged),for: .valueChanged) }
问题:一旦第二次调用选择器,颜色只会改变.
我想,出现这个问题是因为inputView是可选的,只有在第二次调用picker时,inputView才会在我想要更改颜色的时刻实例化.
我试图继承UITextField并观察inputView.
class DateTextField: UITextField { override var inputView: UIView? { didSet { self.inputView?.backgroundColor = Colors.CI1 self.reloadInputViews() } } }
很遗憾没有成功.相同的行为.我错过了什么?非常感谢帮助.
解决方法
您可以使用以下库来自定义颜色
https://github.com/prolificinteractive/PIDatePicker
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。