所以我想将完成按钮移动到工具栏右侧。
这是我的代码: -
我感谢所有答案
let picker=UIDatePicker()
func createDatePicker() {
let toolbar = UIToolbar()
toolbar.sizeToFit()
// done button for toolbar
let done = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: #selector(donePressed))
toolbar.setItems([done], animated: false)
tanggalLahirTextField.inputAccessoryView = toolbar
tanggalLahirTextField.inputView = picker
picker.datePickerMode = .date
}
答案 0 :(得分:1)
在左侧添加灵活空间,因此您的完成按钮将自动移动到右侧。更新您的代码如下:
let done = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: #selector(donePressed))
// Add this line of code.
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
toolbar.setItems([flexibleSpace, done], animated: false)