iPhone - 如何设置uinavigationbar高度? [英] iPhone - How set uinavigationbar height?

查看:143
本文介绍了iPhone - 如何设置uinavigationbar高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让导航视图的顶部变小一些。你会如何实现这一目标?这是我到目前为止所尝试的,但正如你所看到的,即使我使导航栏变小,它曾经占据的区域仍然存在(黑色)。

I want to make the top of the navigation view a bit smaller. How would you achieve this? This is what I've tried so far, but as you can see, even though I make the navigationbar smaller, the area which it used to occupy is still there (black).

[window addSubview:[navigationController view]];
navigationController.view.frame = CGRectMake(0, 100, 320, 280);
navigationController.navigationBar.frame = CGRectMake(0, 0, 320, 20);
navigationController.view.backgroundColor = [UIColor blackColor];
[window makeKeyAndVisible];

推荐答案

使用自定义sizeThatFits创建UINavigationBar类别。

Create a UINavigationBar Category with a custom sizeThatFits.

@implementation UINavigationBar (customNav)
  - (CGSize)sizeThatFits:(CGSize)size {
    CGSize newSize = CGSizeMake(self.frame.size.width,70);
    return newSize;
  }
@end

这篇关于iPhone - 如何设置uinavigationbar高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆