我想改变 UIPickerView
的背景颜色,这可行吗?
更新:一个简单的技巧是在某些子视图上设置alpha。具体取决于你有多少个组件,但代码如下:
[(UIView*)[[picker subviews] objectAtIndex:2] setAlpha:0.5f];
这将使表盘半透明,并显示背景颜色。
设置backgroundColor似乎没有任何作用。到目前为止,我所能做的最好的事情是设置单个组件行的背景颜色,但这几乎没有用,因为组件的基本颜色仍然是白色。
理想情况下,我想设置每个组件(即表盘)的背景颜色。
最后终于做到了。我试着为一个具有一个组件的 picker view 进行操作。
set the picker view background color to clear color by wizard or by code as follow:
Picker1.backgroundColor = [UIColor clearColor];
Set alpha value to 0.0f for the picker view subviews numbered 0, 1 and 3. (Don't know why there is subview 2 thought). Do it by code after the first load data for the picker view as follow (it will throw an exception if you do this in the DidViewLoad).
[(UIView*)[[Picker1 subviews] objectAtIndex:0] setAlpha:0.0f];
[(UIView*)[[Picker1 subviews] objectAtIndex:1] setAlpha:0.0f];
[(UIView*)[[Picker1 subviews] objectAtIndex:3] setAlpha:0.0f];
Don't forget to clear background color for the label you are sending to the picker view in the viewForRow method.
lbl.backgroundColor = [UIColor clearColor];
似乎iOS 4.2没有任何子视图...
NSLog(@" %@ ", [self.pickerView subviews]);
返回空数组。