how to change the background color in UIPickerView?

后端 未结 4 1575
太阳男子
太阳男子 2021-01-15 06:09

I want to change the background color in UIPickerView, Is it possible?

4条回答
  •  渐次进展
    2021-01-15 06:39

    Finally managed to do it. I try it for a picker view with one component.

    1. set the picker view background color to clear color by wizard or by code as follow:

      Picker1.backgroundColor = [UIColor clearColor];
      
    2. Set alpha value to 0.0f for the picker view subviews numbered 0, 1 and 3. (Don't know why there is subview 2 thought). Do it by code after the first load data for the picker view as follow (it will throw an exception if you do this in the DidViewLoad).

      [(UIView*)[[Picker1 subviews] objectAtIndex:0] setAlpha:0.0f];
      [(UIView*)[[Picker1 subviews] objectAtIndex:1] setAlpha:0.0f];
      [(UIView*)[[Picker1 subviews] objectAtIndex:3] setAlpha:0.0f];
      
    3. Don't forget to clear background color for the label you are sending to the picker view in the viewForRow method.

      lbl.backgroundColor = [UIColor clearColor];
      

提交回复
热议问题