如何使UIBarButtonItem文本在UIPickerView中可见?

时间:2019-04-12 10:55:30

标签: ios swift datepicker uipickerview uidatepicker

有没有人遇到过这样的问题,即在您单击此UIBarButtonItem之前,UIToolbar中的UIBarButtonItem文本(在UIDatePicker中调用)是不可见的?什么原因可能导致此问题?

Here you can not see the buttons

But when you click on the screen where it is supposed to be you can see that it appears

我尝试了一切,但是问题仍然与每个UIPickerView(包括UIDatePicker)有关

这是我的实现方式:

@objc func createDatePicker() {
        datePicker.datePickerMode = .date

        //ToolBar
        let toolbar = UIToolbar();
        toolbar.sizeToFit()
        let doneButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(doneDatePicker));
        let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.flexibleSpace, target: nil, action: nil)
        let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelDatePicker));
        // I've tried to change color of the label, but it didn't help
        //toolbar.tintColor = UIColor.black
        toolbar.setItems([cancelButton,spaceButton,doneButton], animated: false)


        dateTextfield.inputAccessoryView = toolbar
        dateTextfield.inputView = datePicker
    }

使用此代码,这些按钮不可见,但是当您在应该放置这些按钮的地方单击时,将显示被单击按钮的文本。 但是有什么办法可以使它始终可见吗?这样的行为可能是什么原因?

我是ios的新手。因此,我将非常感谢您的帮助!预先感谢。

1 个答案:

答案 0 :(得分:0)

尝试此代码。在这里,我将在文本字段中添加DatePicker开始编辑。

from models import Blog
from forms import BlogForm

class BlogAdmin(ModelAdmin):
    form = BlogForm()