【发布时间】:2010-08-12 15:07:27
【问题描述】:
您好,我想将 UIDatePicker 的背景颜色从当前的光泽图像更改为清除,就像在这个示例中一样
(来源:apple.com)
任何想法如何做到这一点?我试过了
datepicker.backgroundColor = [UIColor clearColor];
但它没有工作。
【问题讨论】:
标签: iphone
您好,我想将 UIDatePicker 的背景颜色从当前的光泽图像更改为清除,就像在这个示例中一样
(来源:apple.com)
任何想法如何做到这一点?我试过了
datepicker.backgroundColor = [UIColor clearColor];
但它没有工作。
【问题讨论】:
标签: iphone
UIDatePicker 包含一个子视图。反过来,该子视图包含形成 UIDatePicker 外观的 15 个其他子视图。它们的第一个和最后一个是背景,因此要使其透明,只需将它们关闭并将主子视图的背景颜色设置为 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];
【讨论】: