How do I change the font size in a UIPickerView in Swift?
Update Swift 4.2
I managed to use the code below:
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var pickerLabel: UILabel? = (view as? UILabel)
if pickerLabel == nil {
pickerLabel = UILabel()
pickerLabel?.font = UIFont(name: "Your Font Name", size: 25)
pickerLabel?.textAlignment = .center
}
pickerLabel?.text = <Data Array>[component][row]
pickerLabel?.textColor = UIColor(named: "Your Color Name")
return pickerLabel!
}
Hopefully help you
Try this for Swift 3.x:
Fill your Font name, Color, Size & Data Array with appropriate values.
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var pickerLabel: UILabel? = (view as? UILabel)
if pickerLabel == nil {
pickerLabel = UILabel()
pickerLabel?.font = UIFont(name: "<Your Font Name>", size: <Font Size>)
pickerLabel?.textAlignment = .center
}
pickerLabel?.text = <Data Array>[row]
pickerLabel?.textColor = UIColor.blue
return pickerLabel!
}
EDIT:
For Multiple components, you can do something like this:
if component == 0 {
var label: UILabel? = (view as? UILabel)
label.text = <Your Arr>[row]
return label
}else {
return anotherLabel
}
Output:
Hope it helps!!!