更改导航栏 iOS Swift 的高度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32142375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the height of the Navigation bar iOS Swift
提问by Skywalker
I am trying to change the height of there navigation bar for my app. Currently the height is fixed to 44. I can change the width from Xcode but not the height.
我正在尝试为我的应用更改导航栏的高度。目前高度固定为 44。我可以从 Xcode 更改宽度,但不能更改高度。
I have no idea how to change this. Very new to iOS development.
我不知道如何改变这一点。iOS 开发的新手。
Can anyone please help?
有人可以帮忙吗?
回答by matt
simply dragged and dropped it on my view
只需将其拖放到我的视图上
In that case, the simplest way is with constraints. Just give it a height constraint (along with the other constraints that position it). No code required! Here's an example:
在这种情况下,最简单的方法是使用约束。只需给它一个高度约束(以及定位它的其他约束)。无需代码!下面是一个例子:
That was achieved with no code at all. It's all done with constraints:
这是完全没有代码的情况下实现的。这一切都是通过约束完成的:
We are pinned to the top and sides of the superview, along with height constraint of 100.
我们固定在超级视图的顶部和侧面,高度约束为 100。
回答by iAnurag
Try this :
尝试这个 :
import UIKit
class YourViewController : UIViewController {
var navBar: UINavigationBar = UINavigationBar()
override func viewDidLoad() {
super.viewDidLoad()
self.setNavBarToTheView()
// Do any additional setup after loading the view.
self.title = "test test"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func setNavBarToTheView() {
self.navBar.frame = CGRectMake(0, 0, 320, 50) // Here you can set you Width and Height for your navBar
self.navBar.backgroundColor = (UIColor.blackColor())
self.view.addSubview(navBar)
}
}
回答by dnaatwork.com
I know this makes no sense, however this is what I did ( worked without laying down constraints ).
我知道这没有任何意义,但这就是我所做的(在没有设置约束的情况下工作)。
- select your View Controller.
- Open Show the attributes inspector
- for top barselect any tab bar(I'm choosing translucent Tab Bar).
- within the show the object librarydrag and drop the navigation itemon the View Controller. (If done right, should look like image 3)
- Additionally ( fyi ), you can add a constraint to your button, etc. with using no margins and top being set to 0.
- 选择您的视图控制器。
- 打开显示属性检查器
- 对于顶部栏,选择任何标签栏(我选择半透明标签栏)。
- 在显示对象库中将导航项拖放到视图控制器上。(如果做得好,应该看起来像图 3)
- 此外(仅供参考),您可以向按钮等添加约束,不使用边距并将顶部设置为 0。