How to change UIPickerView image

二次信任 提交于 2019-12-27 06:01:51

问题


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:


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



来源:https://stackoverflow.com/questions/19046099/how-to-change-uipickerview-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!