Change UIPickerView background

前端 未结 9 1071
天涯浪人
天涯浪人 2020-11-27 15:38

I want to change the border color of a UIPickerView. I do not see a tint property for the UIPickerView. Is there any way this could be done? Or a workaround?

Thanks.

9条回答
  •  日久生厌
    2020-11-27 16:14

    You can do the following:

    set the picker view background colour by wizard or by code as follow:

    Picker1.backgroundColor = [UIColor someColor];// clearColor for transparent
    

    Set alpha value 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:someValue];// 0.0f for transparent
    [(UIView*)[[Picker1 subviews] objectAtIndex:1] setAlpha:someValue];
    [(UIView*)[[Picker1 subviews] objectAtIndex:3] setAlpha:someValue];
    

    Don't forget to clear background color for the label you are sending to the picker view in the viewForRow method.

    lbl.backgroundColor = [UIColor someColor];// could be clearColor
    

提交回复
热议问题