【发布时间】:2018-04-11 04:08:47
【问题描述】:
自定义导航栏高度大于默认值(44pt)后,我想更改右侧导航栏项目按钮的高度,但限制在44pt。我怎样才能让它更高?我知道在 iOS 11 中,按钮现在位于 UIBarButtonStackView 内,似乎我们无法更改堆栈视图框架?
我使用这段代码来改变按钮的宽度和高度:
button.widthAnchor.constraint(equalToConstant: 40).isActive = true
button.heightAnchor.constraint(equalToConstant: 60).isActive = true
button.translatesAutoresizingMaskIntoConstraints = false
button.setImage(image, for: .normal)
let barButton = UIBarButtonItem(customView: button)
self.navigationItem.rightBarButtonItem = barButton
谢谢!
【问题讨论】:
-
看一次可能对你有帮助stackoverflow.com/questions/31940352/…
-
@Anbu.karthik 我要改导航栏项按钮,不是导航栏,你的回答是关于导航栏的。
-
您是否在栏按钮项中设置了任何图像或只是自定义图标?
-
@MdRashedPervez 我确实为栏按钮设置了图像,我已经更新了问题。
-
好的.. 现在我明白了.. 您只能更改项目的宽度而不是高度。高度会根据导航栏的高度自动改变。我会给你下面的代码。
标签: ios swift uinavigationbar