代码之家  ›  专栏  ›  技术社区  ›  Adahan Inc.

如何自定义UItoolbar

  •  0
  • Adahan Inc.  · 技术社区  · 7 年前

    Twitter注册页面

    enter image description here

    大家好,我有一些关于swift 3/4上UItoolBar的垫子

    我想做一个像推特这样的唱歌设计,

    1) 我用代码创建工具栏;

    let toolBar = UIToolbar()
    toolBar.sizeToFit()
    
    let flexibleSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
    let doneButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.done, target: self, action: #selector(self.doneClicked))
    
    
    toolBar.setItems([flexibleSpace, doneButton], animated: false)
    kullaniciAdi.inputAccessoryView = toolBar
    eposta.inputAccessoryView = toolBar
    sifre.inputAccessoryView = toolBar
    

    但我不能在上面添加自定义按钮。比如用我的语言修改“完成”的文本。

    2) 因此,我使用故事板手动创建了一个工具栏,里面有一个按钮和灵活的空间。但是±需要将工具栏“附加”到键盘上,所以当我开始编辑文本字段时,工具栏将自动显示。注意:如果工具栏在不编辑文本字段时也会显示出来,那就太棒了。就像这样:

    我的应用程序正在尝试附加工具栏

    enter image description here

    谢谢大家

    1 回复  |  直到 7 年前
        1
  •  1
  •   McDonal_11    7 年前

    In代码

    let sonrakiButton = UIBarButtonItem(title: "Sonraki", style: UIBarButtonItemStyle.plain, target: self, action: #selector(self.sendDoneBtnAction))
    

    有关更多信息,请阅读此 link