UINavigationController小知识点
1.自定标题的简单两种办法。
方法一、通过UILable来修改.
UILabel* titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];
titleLabel.font = [UIFontboldSystemFontOfSize:20];
titleLabel.textColor = [UIColororangeColor];
titleLabel.textAlignment =NSTextAlignmentCenter;
titleLabel.text = @"自定义标题";
self.navigationItem.titleView =titleLabel;
方式二、通过setTitleTextAttributes来设置属性.
NSDictionary* attr = @{ NSFontAttributeName: [UIFont systemFontOfSize:10],NSForegroundColorAttributeName : [UIColorredColor] };
[self.navigationController.navigationBar setTitleTextAttributes:attr];
2.关于导航条上高斯模糊和背景色问题.
(1)是否关闭高斯模糊 YES---开启模糊, NO---关闭模糊
self.navigationController.navigationBar.translucent= NO;
(2)改主题颜色 setTintColor——设置你的主题颜色
[self.navigationController.navigationBar setTintColor:[UIColororangeColor]];
(3)导航条背景颜色
[self.navigationController.navigationBarsetBackgroundColor:[UIColor purpleColor]];
3.在定义UIBarButtonItem时,记得要让image不进行渲染.
UIImage*image = [UIImage imageNamed:@"图片的名字 "];
image = [imageimageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
这样image就不会被系统渲染成其他样式了,
然后加到barButton上。
UIBarButtonItem*item = [[UIBarButtonItem alloc] initWithImage:imagestyle:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.leftBarButtonItem= item;