Search code examples
swiftuipickerview

Customize the UIPickerView bar Swift


I'm wanting to change the appearance of the bar on the picker view, and I have no idea where I would go about doing this? I would like to make it look like it does in the image. enter image description here

Thank you in advance, all help is appreciated


Solution

    1. Hardcode your background to something like:
      enter image description here

    2. Set your font when selected value changes

      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
                  // ...
              }
          }
      }
      

    For customizing the font, you may need to use pickerView(UIPickerView, viewForRow: Int, forComponent: Int, reusing: UIView?) as noted by Kamran.