gpt4 book ai didi

swift - 如何以编程方式将 UIBarButtonItem 置于屏幕中间?

转载 作者:行者123 更新时间:2023-11-28 05:38:59 25 4
gpt4 key购买 nike

我正在尝试移动中间的 DONE 按钮。 enter image description here

最初,它位于左侧:

let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(ViewController.dismissKeyboard))

toolBar.setItems([doneButton], animated: false)
toolBar.isUserInteractionEnabled = true

您是否知道如何以编程方式将其移动到屏幕中间?我尝试添加灵活的空间,但它不起作用。

最佳答案

您必须使用 SystemItem 创建两个 UIBarButtonItem:.flexibleSpace并添加到工具栏项目的第一个和最后一个项目:

toolBar.setItems([UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil), doneButton, UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)], animated: false)

关于swift - 如何以编程方式将 UIBarButtonItem 置于屏幕中间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57636454/

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