菜鸟教程小白 发表于 2022-12-11 22:19:35

ios - 更改 datePicker 线条和字体颜色


                                            <p><p>有人知道如何更改 UIDatePicker 的线条和字体颜色并避免使用私有(private) Apple api 吗?
我找到了这个,但它是非常肮脏的解决方案:</p>

<pre><code>      datePicker.setValue(UIColor.white, forKey: &#34;textColor&#34;)

      for subview in self.datePicker.subviews {

            if subview.frame.height &lt;= 5 {

                subview.backgroundColor = UIColor.white
                subview.tintColor = UIColor.white
                subview.layer.borderColor = UIColor.white.cgColor
                subview.layer.borderWidth = 0.5            }
      }

      if let pickerView = self.datePicker.subviews.first {

            for subview in pickerView.subviews {

                if subview.frame.height &lt;= 5 {

                  subview.backgroundColor = UIColor.white
                  subview.tintColor = UIColor.white
                  subview.layer.borderColor = UIColor.white.cgColor
                  subview.layer.borderWidth = 0.5
                }
            }
            self.datePicker.setValue(UIColor.white, forKey: &#34;textColor&#34;)
      }
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p><strong>试试这个:</strong></p>

<p> <a href="/image/EXNEO.png" rel="noreferrer noopener nofollow"><img src="/image/EXNEO.png" alt="enter image description here"/></a> </p>

<p><strong>按代码或:</strong></p>

<pre><code>datePicker.setValue(UIColor.red, forKeyPath: &#34;textColor&#34;)
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 更改 datePicker 线条和字体颜色,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/55005425/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/55005425/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 更改 datePicker 线条和字体颜色