簡體   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