将按钮在uitpickerview工具栏中居中

时间:2019-03-28 20:46:49

标签: swift4 uipickerview toolbar

我正在尝试将标题放在UIPickerView工具栏中。以下是我可以选择的最接近的年份(年份)。PickerView Tool Bar

下面是我的代码。

let toolBar = UIToolbar()
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(ViewController.dismissKeyboard))
let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let yearButton = UIBarButtonItem(title: "Year", style: .plain, target: self, action: nil)
    toolBar.setItems([doneButton,spaceButton, yearButton, spaceButton], animated: false)
    toolBar.isUserInteractionEnabled = true
    seasonTextField.inputAccessoryView = toolBar

任何帮助将不胜感激。

0 个答案:

没有答案