自定义 UIPickerView 栏 Swift

Customize the UIPickerView bar Swift

我想更改选择器视图中栏的外观,但我不知道该从哪里开始?我想让它看起来像图像中那样。

提前致谢,感谢所有帮助

  1. 将您的背景硬编码为:

  2. 选择值更改时设置字体

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        for index in 0 ..< self.pickerView(pickerView, numberOfRowsInComponent: component) {
            if index != row {
                // reset to unselected font for this index here
                // ...
            } else {
                // apply the selected font for this index here
                // ...
            }
        }
    }
    

要自定义字体,您可能需要使用 Kamran 指出的 pickerView(UIPickerView, viewForRow: Int, forComponent: Int, reusing: UIView?)