gpt4 book ai didi

ios - UIBarButtonItem 的空间问题

转载 作者:搜寻专家 更新时间:2023-10-31 23:00:46 26 4
gpt4 key购买 nike

我正在尝试使用以下代码将 Cancel UIBarButtonItem 添加到我的导航栏:

func setupNavBar() {
self.navBar = UINavigationBar(frame: CGRectMake(0.0, 0.0, UIScreen.mainScreen().bounds.width, 64.0))

let customNavigationItem = UINavigationItem(title: "Connect Accounts")
let cancelButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Cancel, target: self, action: "cancelClicked")
customNavigationItem.setLeftBarButtonItem(cancelButton, animated: true)

self.navBar.setItems([customNavigationItem], animated: true)

self.view.addSubview(self.navBar)
}

条形按钮完全粘在屏幕边缘,如下所示:

enter image description here

为什么这个按钮看起来粘在屏幕边缘,我怎样才能给它留出间距,这样它就不会粘在那里?请帮忙!

编辑:我的按钮粘在屏幕的左边缘而不是左上角。

最佳答案

添加空间的正确方法是使用 .FixedSpace :

let fixedSpace = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
fixedSpace.width = 10
customNavigationItem.leftBarButtonItems = [fixedSpace, cancelButton]

UIBarButtonSystemItemFixedSpace

Blank space to add between other items. Only the width property is used when this value is set.

Available in iOS 2.0 and later.

关于ios - UIBarButtonItem 的空间问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35791514/

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