Changing text color of datepicker
Found solution at comments of stackoverflow. If you need just to
change text color to yours and assign this subclass you your picker. For whiteColor works as magic.
Only minus i've found that color two lines of selected number is still gray.
class ColoredDatePicker: UIDatePicker {
var changed = false
override func addSubview(view: UIView) {
if !changed {
changed = true
self.setValue(UIColor.whiteColor(), forKey: "textColor")
}
super.addSubview(view)
}
}
Changing font color of Date Picker with inline style
There is no way to change inline
styled Date Picker text color in UIKit
14, but here is a workaround you can try:
Override style
I noticed that if you change the theme of the device (between light and dark), the text color of the .inline
date picker is changing.
So for example if you want a dark-text date picker in dark theme, you can override it:
myDatePicker.overrideUserInterfaceStyle = .light
Heres a image of the result
I will keep this post updated if there is any new way to change to any color.
Change font color in new DatePicker (iOS14)
I don't have your colors but the following should work.
Tested with Xcode 12.1 / iOS 14.1
VStack (alignment: .center, spacing: 0)
{
DatePicker(selection: self.$enddate, in: self.endMinDate()...self.endMaxDate()) {
Text("Start")
}.labelsHidden()
}
.accentColor(MyColor.bluecolor) // << this one !!
//.accentColor(.red) // << used for demo
Change DatePicker Text Color
In styles.xml
:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="android:datePickerStyle">@style/MyDatePickerStyle</item>
</style>
<style name="MyDatePickerStyle" parent="@android:style/Widget.DeviceDefault.DatePicker">
<item name="android:headerBackground">@color/red</item>
<item name="android:headerMonthTextAppearance">@style/MyDatePickerTextAppearance</item>
</style>
<style name="MyDatePickerTextAppearance" parent="TextAppearance.AppCompat.Body1">
<item name="android:textColor">@drawable/my_color_state_list</item>
</style>
drawable/my_color_state_list.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Month color -->
<item android:color="@color/yellow" android:state_selected="true"/>
<!-- Year color -->
<item android:color="@color/purple" />
</selector>
If you also want to control the selected date color, then add this theme to style.xml
:
<style name="MyDatePickerTheme" parent="AppTheme">
<item name="colorAccent">@color/blue</item>
</style>
In layout:
<DatePicker
android:theme="@style/MyDatePickerTheme"
.../>
Result:
Change date-picker text color in spinner mode in android?
You can use:
<DatePicker
android:theme="@style/MyDatePicker"
..>
with:
<style name="MyDatePicker" >
<!-- Text color -->
<item name="android:textColorPrimary">@color/....</item>
<!-- Divider color -->
<item name="colorControlNormal">@color/...</item>
</style>
Related Topics
Swift 3 For Loop With Increment
How to Encode Enum Using Nscoder in Swift
Saving Cgimageref to a Png File
Lidar and Realitykit - Capture a Real World Texture For a Scanned Model
Does Swift Have Documentation Generation Support
Iterate Over Collection Two At a Time in Swift
First Item in a List Is Always Selected
Instance Member Cannot Be Used on Type
Dispatch_Once After the Swift 3 Gcd API Changes
How to Update the Constant Height Constraint of a Uiview Programmatically
Swift Closure Async Order of Execution
What's the Simplest Way to Convert from a Single Character String to an Ascii Value in Swift