UIDate Picker背景色 [英] UIDate Picker background color
问题描述
我想将UIDatePicker的背景颜色从当前的光泽图像更改为像本例一样清除
HI I would like to change the background color of the UIDatePicker from the current glossy image to clear just like in this example
(来源:任何想法该怎么做?我尝试过
Any ideas how to do that? I tried
datepicker.backgroundColor = [UIColor clearColor];
datepicker.backgroundColor = [UIColor clearColor];
但是没有用.
推荐答案
UIDatePicker包含一个子视图.该子视图又包含形成UIDatePicker外观的其他15个子视图.它们的第一个和最后一个是背景,因此要使其透明,只需将它们关闭并将主子视图的背景色设置为clearColor:
UIDatePicker contains one subview. That subview, in turn, contains 15 other subviews that form UIDatePicker's appearance. The first and the last of them are the background, so to make it transparent just turn them off and set background color of main subview to clearColor:
// create the picker
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 40, 320, 320)];
// add it to some view first
[actionSheet addSubview:datePicker];
[datePicker release];
// clear the background of the main subview
UIView *view = [[datePicker subviews] objectAtIndex:0];
[view setBackgroundColor:[UIColor clearColor]];
// hide the first and the last subviews
[[[view subviews] objectAtIndex:0] setHidden:YES];
[[[view subviews] lastObject] setHidden:YES];
这篇关于UIDate Picker背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!