UIDatePicker背景色

时间:2010-08-12 15:07:27

标签: iphone

HI我想将当前光泽图像中的UIDatePicker的背景颜色更改为清除,就像在此示例中一样

alt text http://a1.phobos.apple.com/us/r1000/009/Purple/c6/22/0c/mzl.purwdyaq.320x480-75.jpg

任何想法如何做到这一点?我试过了

datepicker.backgroundColor = [UIColor clearColor];

但它没有用。

1 个答案:

答案 0 :(得分:5)

UIDatePicker包含一个子视图。反过来,该子视图包含15个形成UIDatePicker外观的其他子视图。它们的第一个和最后一个是背景,所以为了使它透明,只需关闭它们并将主要子视图的背景颜色设置为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];