如何将导航按钮一直限制在左侧或右侧? (iOS)
How to constrain navigation buttons all the way to the left or right? (iOS)
我试图将导航栏按钮一直左右对齐,因为屏幕边缘和按钮之间有一些 space。关于如何将按钮的前导锚点限制在导航的前缘有什么想法 bar/screen?
添加导航项时,不需要设置约束,需要设置框架。
我遇到过你的问题,目前在 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
}
希望对您有所帮助。
我试图将导航栏按钮一直左右对齐,因为屏幕边缘和按钮之间有一些 space。关于如何将按钮的前导锚点限制在导航的前缘有什么想法 bar/screen?
添加导航项时,不需要设置约束,需要设置框架。
我遇到过你的问题,目前在 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
}
希望对您有所帮助。