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];
这种的被苹果接受?它似乎依赖于内部实现细节,这些细节可能在未来的版本中发生变化。 – 2013-05-04 20:34:50
当然,UIDatePicker的内部实现可能会在未来由Apple改变。至于应用程序审查过程,有几个UI元素不允许更改它们的背景(如UIDatePicker,UISearchBar等),但在某些应用程序中,它们会在默认背景下显得笨拙。虽然这种控制调整不是一种好的做法,但Apple知道UI元素的限制,并允许应用程序包含自定义控件(如果它们看起来不错)。 – Amoneron 2013-05-06 13:27:25
我得考虑一下。我的应用程序对我来说似乎太危险了。我们没有来自客户的维护合同,所以我们必须希望它尽可能长时间地保持活跃,不会受到平台变更的影响。在内部实现方面可能没有问题,但似乎更有可能在下一个版本的iOS中突破,所以我不知道我们是否可以承担风险。无论如何,感谢您的反馈。 – 2013-05-06 16:56:19