UINavigationBar基本设置

来源:互联网 发布:出名的网络大电影 编辑:程序博客网 时间:2024/05/17 02:55

 UINavigationBar *navigationBar = [UINavigationBar appearance];

 1、//设置UINavigationBar背景色

 navigationBar.barTintColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];

 2、//设置UINavigationBar字体颜色

navigationBar.tintColor = [UIColor whiteColor];

 [navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];         

或者[bar setTitleTextAttributes:@{UITextAttributeTextColor : [UIColor whiteColor]}];

3、上文提到的setTitleTextAttributes:...,主要是设置字体的大小、颜色、字体等的数据集合

[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

 [UIColor colorWithRed:0 green:0 blue:0 alpha:1], UITextAttributeTextColor,

 [UIColor colorWithRed:0 green:0 blue:0 alpha:1], UITextAttributeTextShadowColor,

[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset,

[UIFont fontWithName:@"Arial-Bold" size:0.0], UITextAttributeFont, nil]];

4、另:状态栏字体设置

(1)、[[UIApplicationsharedApplication]setStatusBarStyle:UIStatusBarStyleLightContentanimated:YES];

(2)、Your ViewController is inside a navigationController then the navigationController’s navigationBar.barStyle determines the statusBarStyle.

self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;//使用UINavigationController时才能设置状态栏字体颜色.



0 0