【问题标题】:How to constrain navigation buttons all the way to the left or right? (iOS)如何将导航按钮一直限制在左侧或右侧? (iOS)
【发布时间】:2019-03-22 07:26:21
【问题描述】:

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

【问题讨论】:

    标签: ios user-interface uinavigationbar


    【解决方案1】:

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

    我遇到了您的问题,目前在 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
    }
    

    我希望这会有所帮助。

    【讨论】:

    • 这是否也会将可点击的触摸区域一直向左移动?
    • @JaeYang 条形按钮项目的各个触摸区域是恒定/静态的。请记住选择问题的答案以关闭它:)
    猜你喜欢
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-02
    • 1970-01-01
    相关资源
    最近更新 更多