如何更改UIPickerView图像 [英] How to change UIPickerView image

查看:179
本文介绍了如何更改UIPickerView图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义水平UIPickerView,如这个
i想要改变图像,如这个

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

我不知道该怎么办。

推荐答案

我试过这段代码

[[[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];

我希望它会帮助你

这篇关于如何更改UIPickerView图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆