navigation导航中导航栏的设置

参看:http://blog.csdn.net/mad1989/article/details/41516743
使用导航navigation时,下一页的标题的设置
1.在进入push下一页时,指定标题

myViewContoller *view=[[myViewContoller alloc]init];
[sself.navigationController pushViewController:view animated:NO];
view.title=@“标题”;

2。进入该页后设置
(1)简单的设置标题以及标题的背景色
通过navigationItem的title属性直接设置标题。
//设置当前页导航栏以及以后从此页push的页面的导航栏的样式,
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor,nil]];
结果:把背景改成了蓝色,title文字改成了白色,NavigationBar及其push过去的子页面也会是你修改后的背景颜色

//在appDelegate中设置NavigationBar背景颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
//@{}代表Dictionary
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
结果:所有页面的导航栏均设置为红色
在导航栏使用背景图片:
如果您的应用程序使用了自定义图像作为栏的背景,你需要提供一个“更大”的图片,使其延伸了状态栏的后面。导航栏的高度现在是从44点(88像素)更改为64点(128像素)。
仍然可以使用了setBackgroundImage:方法来指定自定义图像的导航栏。下面是代码行设置背景图片:
1. [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@”nav_bg.png”] forBarMetrics:UIBarMetricsDefault];

改变导航栏标题的字体

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

  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(0, 1);
  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]];

通过navigationItem的titleView自定义标题,标题背景可设置为图片等
1. self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@”appcoda-logo.png”]];
2. 添加多个栏按钮项目
您希望添加导航栏的一侧不止一个栏按钮项目,无论是leftBarButtonItems和rightBarButtonItems 您在导航栏左侧/右侧指定自定义栏按钮项目。比如你想添加一个摄像头和一个共享按钮右侧的吧。您可以使用下面的代码:

  1. UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action: nil nil];
  2. UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action: nil nil];
  3. NSArray *itemsArr = @[shareItem,cameraItem];
  4. self.navigationItem.rightBarButtonItems = itemsArr;
    3.自定义后退按钮的文字和颜色
    通常情况下,我们使用UINavigationController时,push到的子页面,左上角会是系统自动取值上一层父页面的title名称,默认情况是这样,那么我们该如何修改它呢?通过设置navigationItem的backBarButtonItem可以直接更换文字UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@”返回” style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;

发现文字颜色和背景有重复,那么如何自定义其颜色呢?
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员的修养

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值