繁体   English   中英

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

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

我试图将导航栏按钮一直左右对齐,因为屏幕边缘和按钮之间有一些空间。 任何想法如何将按钮的前导锚点约束到导航栏/屏幕的前导边缘?

添加导航项时,您不需要设置约束,而是需要设置框架。

我遇到了您的问题,目前在 iOS 11 上遇到了它。我使用的一个快速解决方案是添加一个清晰的负间隔条按钮。 像这样:

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
}

我希望这有帮助。

暂无
暂无

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

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