How to change UIPickerView image

2019-09-27 15:59发布

i have a custom horizontal UIPickerView like this i want to change the image like this

and i don't know how to do .

1条回答
倾城 Initia
2楼-- · 2019-09-27 16:22

i have tried this code

[[[self._picker1  subviews] objectAtIndex:3] setAlpha:0.0]; // this view contains the background so you can change it with your new background
// object at index 4 is your labels or images so they must be shown
[[[self._picker1  subviews] objectAtIndex:5] setAlpha:0.0];
[[[self._picker1  subviews] objectAtIndex:6] setAlpha:0.0];// this is you indicator , you can add another custom one or hide it as i do

//other views are about shadow in the right and left i set the alpha to 0.0 and i can also remove them
[[[self._picker1  subviews] objectAtIndex:7] setAlpha:0.0];
[[[self._picker1  subviews] objectAtIndex:8] setAlpha:0.0];
[[[self._picker1  subviews] objectAtIndex:0] setAlpha:0.0];
[[[self._picker1  subviews] objectAtIndex:1] setAlpha:0.0];

and to set the custom image here is the code

UIView * viewForPickerView1 = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, self._picker1.frame.size.width, self._picker1.frame.size.height)];
[viewForPickerView1 setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"picker1.png"]]];
[[[self._picker1  subviews] objectAtIndex:2] addSubview:viewForPickerView1];

i hope that it will help you

查看更多
登录 后发表回答