Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change colour of UIPickerView selection indicators

Our UIPickerView has a dark background and the selection lines are incredibly hard to see. Is there anyway to change them to a colour of my choosing?

Update: I'm talking about the --- above and below the "Panda" item.

    Cat
    Dog
  Elephant
-----------
   Panda
-----------
   Bear
  Giraffe
like image 367
cjhill Avatar asked Nov 30 '22 18:11

cjhill


1 Answers

Swift 4.2

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

        pickerView.subviews[1].backgroundColor = UIColor.white
        pickerView.subviews[2].backgroundColor = UIColor.white

        return view
    }

This works for me!

like image 76
Dian Avatar answered Dec 06 '22 01:12

Dian