gpt4 book ai didi

ios - 如何同时设置keyboardAppearance和inputView?.backgroundColor为dark?

转载 作者:可可西里 更新时间:2023-11-01 01:56:18 25 4
gpt4 key购买 nike

我有 datePicker,我将其设置为 textFieldinputView

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var textField: UITextField!
var datePicker: UIDatePicker = UIDatePicker()

override func viewDidLoad() {
super.viewDidLoad()

datePicker.datePickerMode = .date
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
textField.inputView = datePicker

textField.keyboardAppearance = .dark
textField.inputView?.backgroundColor = #colorLiteral(red: 0.07627698034, green: 0.1097967997, blue: 0.1355849206, alpha: 1)
}

}

我想同时拥有深色工具栏和深色 UIDatePicker 背景。但是,实际上,textField.inputView?.backgroundColor 不起作用。 enter image description here

但是如果我评论 textField.keyboardAppearance = .dark,datepicker 的背景会改变:

enter image description here

如何修复?

最佳答案

我认为使用datePicker,您不需要这个toolBar。你可以按照下面的方式摆脱它,

override func viewDidLoad() {
super.viewDidLoad()

datePicker.datePickerMode = .date
datePicker.setValue(UIColor.white, forKeyPath: "textColor")
textField.inputView = datePicker

datePicker.backgroundColor = .black
textField.inputAssistantItem.leadingBarButtonGroups = []
textField.inputAssistantItem.trailingBarButtonGroups = []
}

如果你也想要 toolBar 那么你可以设置一个自定义 toolBarblack background color 如下,

let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 50))
toolbar.barTintColor = .black
toolbar.isTranslucent = false // Set to true to give some contrast.

textField.inputAccessoryView = toolbar

关于ios - 如何同时设置keyboardAppearance和inputView?.backgroundColor为dark?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53092719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com