本文介绍了如何更改UIDatePicker的线条颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个ViewController中有一个UIDatePicker。如您所见,背景是黑暗的。

I have got a UIDatePicker in one of my ViewControllers. As you can see, the background is dark.

我已经设法将文字颜色更改为白色。我唯一不能更改的是所选日期上下两行的颜色。它始终保持默认的深灰色。苹果文档说,有没有人能打断代码来为这些行加上颜色?

What i already managed to change is the text color to white. What i just can't change is the color of the two lines above and below the selected date. It always remains default dark grey. Does anyone have a code snipped to achieve coloring these lines?

推荐答案

首先,苹果公司说,大约 Date Pickers ,您无法自定义日期选择器的外观。

To start with, Apple docs says, about Date Pickers, "You cannot customize the appearance of date pickers."

话虽如此,以下代码正是您所需要的。我了解这不是最精美的代码,但在这里是

That being said, the following code does exactly what you need. I understand it's not the most elegant piece of code, but here it is

datePicker.subviews[0].subviews[1].backgroundColor = UIColor.redColor()
datePicker.subviews[0].subviews[2].backgroundColor = UIColor.redColor()

UIDatePicker有一个子视图UIDatePickerView,它有3个子视图,其中2个是表示选择行的两行。

UIDatePicker has a subview, UIDatePickerView, which has 3 subviews, 2 of the latter of which are the two lines that indicate the selection row.

这篇关于如何更改UIDatePicker的线条颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:25