Hello,
I have successfully implemented a UIPickerView as the inputView of my custom textField. Because its a hand made UIPickerView, I add 3 labels next to each component to indicate (hour, minute, second)
Now it seem the inputView is autosized based on wdith and device orientation and my UIPickerView adapts to it. This is fine and all but the UILabels mentioned above, do not autosize. I tried various methods but can't seem to adjust it dependent on width or rotation.
Heres my code (within the UITextField subclass)
var picker:UIPickerView = UIPickerView()
override func awakeFromNib() {
super.awakeFromNib()
picker.delegate = self
picker.dataSource = self
(pickerHours,pickerMinutes,pickerSeconds) = MakeTimeFromString(self.text!)
self.inputView = configurePicker()
self.inputAccessoryView = configureAccessoryView()
}
func configurePicker() -> UIView {
picker.backgroundColor = UIColor.clearColor()
let hoursLabel: UILabel = UILabel(frame: CGRectMake((picker.frame.size.width / 3) - 30, 95, 75, 30))
hoursLabel.text = "hour"
hoursLabel.textColor = UIColor.whiteColor()
picker.addSubview(hoursLabel)
let minutesLabel: UILabel = UILabel(frame: CGRectMake((picker.frame.size.width / 2) + 25, 95 , 75, 30))
minutesLabel.text = "min"
minutesLabel.textColor = UIColor.whiteColor()
picker.addSubview(minutesLabel)
let secondsLabel: UILabel = UILabel(frame: CGRectMake(((picker.frame.size.width / 3) * 2) + 75, 95, 75, 30))
secondsLabel.text = "sec"
secondsLabel.textColor = UIColor.whiteColor()
picker.addSubview(secondsLabel)
picker.selectRow(pickerHours, inComponent: 0, animated: true)
picker.selectRow(pickerMinutes, inComponent: 1, animated: true)
picker.selectRow(pickerSeconds, inComponent: 2, animated: true)
return picker
}