Change UIPickerView background

前端 未结 9 1052
天涯浪人
天涯浪人 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:17

    Here is a modern, pixel-perfect version w/ ARC of @Lukas 's answer, because some questions never go out of style:

    #import 
    
    // . . .
    
    CALayer* mask = [[CALayer alloc] init];
             mask.backgroundColor = [UIColor blackColor].CGColor;
             mask.frame = CGRectInset(picker.bounds, 10.0f, 10.0f);
             mask.cornerRadius = 5.0f;
             picker.layer.mask = mask;
    

    This answer works for ANY size of picker b/c the layer dimensions are calculated on-the-fly.

                                                                     enter image description here

提交回复
热议问题