导航栏背景颜色,字体颜色

设置背景颜色

设置背景颜色前,先把透明度设置为no


self.navigationController.navigationBar.translucent = NO;//设置导航栏不透明

self.navigationController.navigationBar.barTintColor = [UIColor blueColor];//导航栏颜色


方法二


  1. //设置NavigationBar背景颜色  
  2. [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];  
  3. //@{}代表Dictionary  
  4. [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; 



在导航栏使用背景图片:

如果您的应用程序使用了自定义图像作为栏的背景,你需要提供一个“更大”的图片,使其延伸了状态栏的后面。导航栏的高度现在是从44点(88像素)更改为64点(128像素)。
仍然可以使用了setBackgroundImage:方法来指定自定义图像的导航栏。下面是代码行设置背景图片:

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];  

效果图和上面的一样,我就不贴出来了。


改变导航栏标题的字体

就像iOS 6,我们可以通过使用导航栏的“titleTextAttributes”属性来自定义的文本样式。可以指定字体,文字颜色,文字阴影颜色,文字阴影在文本标题偏移属性字典,使用下面的文本属性键:

UITextAttributeFont - 字体
UITextAttributeTextColor - 文字颜色
UITextAttributeTextShadowColor - 文字阴影颜色
UITextAttributeTextShadowOffset - 偏移用于文本阴影

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. NSShadow *shadow = [[NSShadow alloc] init];  
  2. shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];  
  3. shadow.shadowOffset = CGSizeMake(01);  
  4. [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:  
  5. [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,  
  6. shadow, NSShadowAttributeName,  
  7. [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil nil]]; 

使用图片作为导航栏标题

不想标题栏是光秃秃的文字?可以通过使用代码行中的图像或标志取代它:简单地改变titleview用来自定义,(适用于较低版本)

[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appcoda-logo.png"]];  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值