iOS开发 UI高级 标签栏和导航栏的设置
2016-08-15 19:40
330 查看
1、标签控制器的相关设置
// 设置正常状态下的属性字典
NSDictionary *normalDic = [NSDictionary dictionary];
normalDic = @{NSFontAttributeName:[UIFont systemFontOfSize:12],
NSForegroundColorAttributeName:[UIColor grayColor]
};
// 设置高亮状态下的属性字典
NSDictionary *heigthDic = [NSDictionary dictionary];
heigthDic = @{NSForegroundColorAttributeName:[UIColor darkGrayColor],
NSFontAttributeName:[UIFont systemFontOfSize:12]
};
2、 通过appearance统一设置UITabBaiItem的文字属性
注意:后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象来统一设置
UITabBarItem *item = [UITabBarItem appearance];
// 普通状态下
[item setTitleTextAttributes:normalDic forState:UIControlStateNormal];
// 高亮状态下
[item setTitleTextAttributes:heigthDic forState:UIControlStateHighlighted];
// 设置控制器相关属性
3、 通过封装方法来设置子控制的相关属性,减少代码冗余量
-(void)setChildVc:(UIViewController *)vc withTitle:(NSString *)title withImage:(NSString *)image withSelectedImage:(NSString *)selectedImage{
//设置控制器的标题和图片属性
vc.tabBarItem.title = title;
vc.tabBarItem.image = [UIImage imageNamed:image];
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
// 设置背景颜色
vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
// 添加子控制器
[self addChildViewController:vc];
}
注意:导航栏的设置补充(因为之前写过导航栏的相关设置,所以这里是补充之前没涉及到的)
4、用图片设置导航栏的标题
self.navigationItem.titleView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"MainTitle"]];
5、自定义导航栏
// 当第一次使用这个类的时候会调用一次
+(void)initialize{
UINavigationBar *bar = [UINavigationBar appearance];
[bar setBackgroundImage:[UIImage imageNamed:@“1.jpg”] forBarMetrics:UIBatMetricsDefault];
}
// 可以在这个方法中设置所有push进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
}
// 设置正常状态下的属性字典
NSDictionary *normalDic = [NSDictionary dictionary];
normalDic = @{NSFontAttributeName:[UIFont systemFontOfSize:12],
NSForegroundColorAttributeName:[UIColor grayColor]
};
// 设置高亮状态下的属性字典
NSDictionary *heigthDic = [NSDictionary dictionary];
heigthDic = @{NSForegroundColorAttributeName:[UIColor darkGrayColor],
NSFontAttributeName:[UIFont systemFontOfSize:12]
};
2、 通过appearance统一设置UITabBaiItem的文字属性
注意:后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象来统一设置
UITabBarItem *item = [UITabBarItem appearance];
// 普通状态下
[item setTitleTextAttributes:normalDic forState:UIControlStateNormal];
// 高亮状态下
[item setTitleTextAttributes:heigthDic forState:UIControlStateHighlighted];
// 设置控制器相关属性
3、 通过封装方法来设置子控制的相关属性,减少代码冗余量
-(void)setChildVc:(UIViewController *)vc withTitle:(NSString *)title withImage:(NSString *)image withSelectedImage:(NSString *)selectedImage{
//设置控制器的标题和图片属性
vc.tabBarItem.title = title;
vc.tabBarItem.image = [UIImage imageNamed:image];
vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImage];
// 设置背景颜色
vc.view.backgroundColor = [UIColor colorWithRed:arc4random_uniform(100)/100.0 green:arc4random_uniform(100)/100.0 blue:arc4random_uniform(100)/100.0 alpha:1.0];
// 添加子控制器
[self addChildViewController:vc];
}
注意:导航栏的设置补充(因为之前写过导航栏的相关设置,所以这里是补充之前没涉及到的)
4、用图片设置导航栏的标题
self.navigationItem.titleView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"MainTitle"]];
5、自定义导航栏
// 当第一次使用这个类的时候会调用一次
+(void)initialize{
UINavigationBar *bar = [UINavigationBar appearance];
[bar setBackgroundImage:[UIImage imageNamed:@“1.jpg”] forBarMetrics:UIBatMetricsDefault];
}
// 可以在这个方法中设置所有push进来的控制器
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
}
相关文章推荐
- iOS开发UI高级—12ios应用数据存储方式(偏好设置)
- ios开发 UI高级 间距设置
- iOS开发 设置整个导航栏背景图、字体及标签栏更改选中背景图的颜色
- iOS开发UI高级—18Quartz2D简单介绍
- Cocos2d-x游戏开发之CCLabelTTF标签详解之Create方法(设置自动换行的标签)和换行符的巧妙使用(十六)(高级篇) (转)
- iOS开发UI高级—27Quartz2D使用(截屏)
- iOS开发UI高级—09控制器的View的创建
- iOS开发UI高级—01常见的项目文件介绍
- iOS开发UI高级—32核心动画简介
- iOS开发UI高级—21Quartz2D使用(图形上下文栈)
- iOS开发UI高级—26Quartz2D使用(信纸条纹)
- iOS开发学习之#标签栏控制器#(6)设置标签栏控制器
- iOS开发高级技巧-运行时属性runtime attribute设置视图圆角
- iOS开发UI高级—29CAlayer(创建图层)
- iOS开发UI高级—34核心动画(关键帧动画)
- iOS开发UI高级—24Quartz2D简单使用(三)
- iOS开发UI高级—04多控制器和导航控制器简单介绍
- iOS开发UI高级—02程序启动原理和UIApplication
- iOS开发UI高级—14UITabBarController简单介绍
- iOS开发UI高级—30CAlayer层的属性