您的位置:首页 > 产品设计 > UI/UE

UINavgationViewController

2015-10-20 14:26 267 查看

一. 设置全部导航条的背景

// 取出全部导航条

UINavigationBar *bar = [UINavigationBar appearance];

// 设置全部导航条的背景图片

[bar setBackgroundImage:[UIImage imageName: @"navigationbar_background.png"] forBarMetrics:UIBarMetricsDefault];

// 导航栏上有一层BackgroundImageView,不能直接设置背景颜色,设置背景颜色是无效的

// bar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"navigationbar_background.png"]];

// 设置导航栏文字的主题

[bar setTitleTextAttributes:@{

UITextAttributeTextColor : [UIColor darkGrayColor] UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero]

}];

二.设置导航条上所有Item

// 设置全部item的背景

// 取出导航条上所有item

UIBarButtonItem *items = [UIBarButtonItem appearance];

// 设置item的背景

[items setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

[items setBackgroundImage:[UIImage imageNamed:@"navigationbar_button_background_pushed.png"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

// 设置item的文字主题

NSDictionary *dict = @{UITextAttributeTextColor : [UIColor darkGrayColor],

UITextAttributeTextShadowOffset : [NSValue valueWithUIOffset:UIOffsetZero],

UITextAttributeFont : [UIFont systemFontOfSize:13]

};

[items setTitleTextAttributes:dict forState:UIControlStateNormal];

[items setTitleTextAttributes:dict forState:UIControlStateHighlighted];

三.设置状态栏模式

// 设置状态栏,因为给导航条设置了颜色,状态栏会随着导航条的颜色改变而改变,所以我们需要设置为黑色。

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;

四.导航控制器不能设置左右item和中间的文字,导航控制器本身不具备显示功能,他是通过跟控制器显示的,不要傻乎乎的给导航控制器设置左右item。

五.如果需要在跳转页面的时候,做一些操作效果,可以自定义导航控制器重写push或者pop方法(重写这个方法,也可以取消一些不想要的效果),或者作为导航控制器的代理,监听跳转方法。

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: