简体   繁体   English

如何限制导航按钮一直向左或向右? (iOS)

[英]How to constrain navigation buttons all the way to the left or right? (iOS)

I am trying to align the navigation bar buttons all the way to the right and left because there is some space between the edge of the screen and the buttons.我试图将导航栏按钮一直左右对齐,因为屏幕边缘和按钮之间有一些空间。 Any ideas how to constrain the leading anchor of the button to the leading edge of the navigation bar/screen?任何想法如何将按钮的前导锚点约束到导航栏/屏幕的前导边缘?

When adding navigation items, you do not need to set constraints, but rather, frames.添加导航项时,您不需要设置约束,而是需要设置框架。

I've experienced your issue and currently experiencing it on iOS 11. A quick solution that I use is to add a clear negative spacer bar button.我遇到了您的问题,目前在 iOS 11 上遇到了它。我使用的一个快速解决方案是添加一个清晰的负间隔条按钮。 Like so:像这样:

internal lazy var button_Skip: UIButton = {
    let button = UIButton(type: .custom)
    button.setup("SKIP".localized(), normalTextColor: .blue)
    button.isHidden = true
    return button
}()

let barButton = UIBarButtonItem(customView: self.button_Skip)
self.button_Skip.frame = CGRect(x: 0, y: 0, width: 55.0, height: 44.0)
let negativeSpacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonItem.SystemItem.fixedSpace, target: nil, action: nil)
if #available(iOS 11.0, *) {
    negativeSpacer.width = -10.0
}

I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM