Customizing UIPickerView (background and spacing)

前端 未结 4 1545
無奈伤痛
無奈伤痛 2020-12-31 22:07

I would like to change the white background in a UIPickerView to an image of my own.

Is this possible?

Also, I have managed to get my UIPickerView to scroll

4条回答
  •  失恋的感觉
    2020-12-31 22:48

    I just figured out how to apply background color or image in the picker view. Hope it may help someone.

    Just define a category in the file where you want to you picker view as follow:

    @implementation UIPickerView(Extension)
    
    -(void)drawRect:(CGRect)rect
    {
    
        NSArray* subviews = [self subviews];
        for(UIView* view in subviews)
        {
            if([view isKindOfClass:[UITableView class]])
            {
                view.backgroundColor = appColor;
            }
        }
        [super drawRect:rect];
    }
    
    @end
    

    You can look further at subviews for more customization.

提交回复
热议问题