How do I change the font size in a UIPickerView in Swift 3?

笑着哭i 提交于 2019-11-30 17:37:26

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!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!