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

UINavigationController之NavigationBar

2016-02-29 14:09 465 查看
参考文章 自定义iOS7导航栏背景,标题和返回按钮文字颜色

获取导航控制器的导航条
UINavigationBar *navBar = self.navigationController.navigationBar;

设置导航条的样式
navBar.barStyle = UIBarStyleDefault;
UIBarStyleDefault           白色半透明
UIBarStyleBlack             黑色半透明
UIBarStyleBlackOpaque       黑色半透明
UIBarStyleBlackTranslucent  黑色半透明

设置导航条半透明或不透明,YES半透明,NO不透明
self.view的坐标原点YES半透明时为屏幕左上角,如果不透明从导航条左下角
navBar.translucent = NO;

设置导航条的镂空颜色
navBar.tintColor = [UIColor whiteColor];

设置导航条的背景颜色
navBar.barTintColor = [UIColor magentaColor];

设置导航条的背景图片
导航条高度为44个坐标点。关于图片的设置,图片的高度刚好是(44、88、132个像素高的时候),
状态栏是紧靠在导航条上。如果图片高度过大或过小,图片会被拉伸或压缩为64坐标点高,状态栏浮在导航条上方
[navBar setBackgroundImage:[UIImage imageNamed:@"nav.png"] forBarMetrics:UIBarMetricsDefault];
UIBarMetricsDefault         纵屏不带备注
UIBarMetricsCompact         横屏不带备注
UIBarMetricsDefaultPrompt   纵屏带备注
UIBarMetricsCompactPrompt   横屏带备注

设置导航标题的文字字体和颜色
navBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor whiteColor]};

navBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],UITextAttributeTextColor};

navBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};


关于UINavigationBar appearance

设置导航条的背景颜色

[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];

设置导航条的背景图片

如果您的应用程序使用了自定义图像作为栏的背景,你需要提供一个“更大”的图片,使其延伸了状态栏的后面。
导航栏的高度现在是从44点(88像素)更改为64点(128像素)。
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bg_nav.png"] forBarMetrics:UIBarMetricsDefault];

设置导航条的镂空颜色

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

设置导航条的字体

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

改变导航条标题的字体

可以通过使用导航栏的“titleTextAttributes”属性来自定义的文本样式。可以指定字体,文字颜色,文字阴影颜色,文字阴影在文本标题偏移属性字典,使用下面的文本属性键:
UITextAttributeFont - 字体
UITextAttributeTextColor - 文字颜色
UITextAttributeTextShadowColor - 文字阴影颜色
UITextAttributeTextShadowOffset - 偏移用于文本阴影

NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];
shadow.shadowOffset = CGSizeMake(0, 1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
shadow, NSShadowAttributeName,
[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil]];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: