[英]How to customize the UIDatePicker and change the text color and the background color?
我在表格单元格中创建了日期对象的格式化显示,并使用UIDatePicker编辑这些值。
但我无法编辑文本的色调颜色和背景颜色。
第一个屏幕截图是实际不需要的结果:
第二个屏幕截图是所需的结果:
以下是该项目的链接: https : //www.dropbox.com/sh/m74tnghpqeah8o7/AAA-rMlGe_mhqiuEkDhbApsUa?dl=0
@AziCode
如果你想使用UiColor获得确切的颜色使用RGB颜色编码,请在func updateDatePicker()中添加以下行
targetedDatePicker.backgroundColor = UIColor.blueColor()
targetedDatePicker.setValue(UIColor.greenColor(), forKeyPath: "textColor")
targetedDatePicker.setValue(0.8, forKeyPath: "alpha")
并参考相同示例的链接和示例代码: - http://blog.deeplink.me/post/81386967477/how-to-easily-customize-uidatepicker-for-ios
Normaly我有个好主意,但只是更改字体颜色:
[self.datePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"];
SEL selector = NSSelectorFromString( @"setHighlightsToday:" );
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature :
[UIDatePicker
instanceMethodSignatureForSelector:selector]];
BOOL no = NO;
[invocation setSelector:selector];
[invocation setArgument:&no atIndex:2];
[invocation invokeWithTarget:self.datePicker];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.