猿问

iOS navigationbar的高度可以修改吗?

如题iOS 中navigationbar的高度可以修改吗?

不负相思意
浏览 1863回答 3
3回答

梵蒂冈之花

为什么我的不改变,我使用的是 ios9 xcode7

红糖糍粑

这样写确实可以修改 UINaigationBar 的高度,但存在一个问题,高度多出的部分会覆盖 ViewController 的视图(ViewController 在有导航栏的情况下视图默认会向下便宜 44)。解决办法是通过创建 UINaigationBar 的子类或 Category 重写 - (CGSize)sizeThatFits:(CGSize)size ,这样视图会自动向下偏移合适的距离。

RISEBY

答案是可以修改的。修改前:修改后:你新建一个工程,将UIWindow的rootViewController设置为一个UINavigationController的实列,然后自定义一个控制器CustomVC,在CustomVC中写如下代码:- (void)viewDidAppear:(BOOL)animated{&nbsp; &nbsp; [super viewDidAppear:animated];&nbsp; &nbsp; NSLog(@"修改前");&nbsp; &nbsp; [self printViewHierarchy:self.navigationController.navigationBar];&nbsp; &nbsp; //修改NavigaionBar的高度&nbsp; &nbsp; self.navigationController.navigationBar.frame = CGRectMake(0, 20, 320, 100);&nbsp; &nbsp; NSLog(@"\n修改后");&nbsp; &nbsp; [self printViewHierarchy:self.navigationController.navigationBar];}- (void)printViewHierarchy:(UIView *)superView{&nbsp; &nbsp; static uint level = 0;&nbsp; &nbsp; for(uint i = 0; i < level; i++){&nbsp; &nbsp; &nbsp; &nbsp; printf("\t");&nbsp; &nbsp; }&nbsp; &nbsp; const char *className = NSStringFromClass([superView class]).UTF8String;&nbsp; &nbsp; const char *frame = NSStringFromCGRect(superView.frame).UTF8String;&nbsp; &nbsp; printf("%s:%s\n", className, frame);&nbsp; &nbsp; ++level;&nbsp; &nbsp; for(UIView *view in superView.subviews){&nbsp; &nbsp; &nbsp; &nbsp; [self printViewHierarchy:view];&nbsp; &nbsp; }&nbsp; &nbsp; --level;}输出结果:UINavigationBar:{{0, 20}, {320, 44}}&nbsp; &nbsp; _UINavigationBarBackground:{{0, 0}, {320, 44}}&nbsp; &nbsp; &nbsp; &nbsp; UIImageView:{{0, 44}, {320, 3}}&nbsp; &nbsp; UINavigationItemView:{{160, 22}, {0, 0}}2013-10-29 20:24:36.900 Nav[8957:907]&nbsp;修改后UINavigationBar:{{0, 20}, {320, 100}}&nbsp; &nbsp; _UINavigationBarBackground:{{0, 0}, {320, 100}}&nbsp; &nbsp; &nbsp; &nbsp; UIImageView:{{0, 100}, {320, 3}}&nbsp; &nbsp; UINavigationItemView:{{160, 22}, {0, 0}}可以看到UINaigationBar的高度已经从44变到了100. 如果还有疑问,请追问。没有的话,请采纳,谢谢!
随时随地看视频慕课网APP

相关分类

iOS
我要回答