How to change the background color of a UIPickerView on iPhone

In my application, I used the view controller. Now I want to change the background color. So, how can I change the background color in select mode, and also want to change the background color of the string. I want to change the default layout color in selection mode, and is it possible to set a custom image as a wallpaper? So please guide me.

+4
source share
5 answers

I have already answered a similar question . You can change the background color by completely replacing the background image using the IXPickerOverlayView class ( available on GitHub ).

+1
source

you can add a UIView to the components of a UIPickerView , but you cannot change the background color or hue color.

  • viewForRow:forComponent for views.
0
source

Finally managed to do it. I am trying to use it to view with one component.

set the background color in selection mode with the wizard or code as follows:

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

Set the alpha value for the subviews of the selection view, numbered 0, 1, and 3. (I don't know why the thought of viewing 2 comes up). Do this by the code after the first load data for the picker view, as it should (this will throw an exception if you do this in 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]; 

Remember to clear the background color for the label that you submit to the selection view in the viewForRow method.

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

Recently, I wrote an article only in this section . It's pretty easy to achieve what you want to do. (Although the article is about iOS7, the technology for providing views rather than strings for your component strings works regardless of the current version of iOS.)

0
source

I changed the background color of the UIPicker and the font color and color of the UIPicker panel. Let the name of your UIPickerView appear as pickerView.

pickerView.backgroundColor = [UIColor greenColor]; - In the greenColor place you can use any color

pickerView.backgroundColor = [UIColor colorWithRed: 127 green: 127 blue: 127 alpha: 1]; - Here you can specify any color code of your choice.

Suppose you took a toolbar in a UIPickerView, then we can change the color using toolBar.backgroundcolor = [UIColor greenColor]; - In the greenColor place you can use any color

toolBar.backgroundColor = [UIColor colorWithRed: 127 green: 127 blue: 127 alpha: 1]; - Here you can specify any color code of your choice.

toolBar.backgroundImage = [UIImage imageWithName: @ "imageName"]; - You can set the image as backgroundImage in the toolbar.

0
source

Source: https://habr.com/ru/post/1340424/


All Articles