简体   繁体   中英

how to change the font size of picker view in autolayout

在此处输入图片说明

i am trying to fix the autolayout of my picker view, at the iPhone (compact width and regular height) it seems Okay, but for iPad ( regular width and regular height), it seems the size of the font of my picker view remains the same as the iPhone, I want the font size of my picker view in iPad little bit bigger, I usually add customization for the font size of regular width and regular height, but there is no option to adjust the font size of picker view in the interface builder.

what should I do?

This can´t be done in the Interface Builder, you need to do it programmatically. It´s kind of easy, do it like this:

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
    let pickerLabel = UILabel()
    if UIDevice.current.userInterfaceIdiom == .pad {
        pickerLabel.font = UIFont.systemFont(ofSize: 16)
        pickerLabel.text = "Row \(row)"
    } else if UIDevice.current.userInterfaceIdiom == .phone {
        pickerLabel.font = UIFont.systemFont(ofSize: 14)
        pickerLabel.text = "Row \(row)"
    }
    return pickerLabel
}

If you´re using pickerView titleForRow you need to remove that function to be able to use viewForRow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM