IOS开发中设置导航栏主题

发表于:2015-7-10 10:16

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:MicLEO    来源:51Testing软件测试网采编

/**
*  系统在第一次使用这个类的时候调用(1个类只会调用一次)
*/
+ (void)initialize
{
// 设置导航栏主题
UINavigationBar *navBar = [UINavigationBar appearance];
// 设置背景图片
NSString *bgName = nil;
if (iOS7) { // 至少是iOS 7.0
bgName = @"NavBar64";
} else { // 非iOS7
bgName = @"NavBar";
}
[navBar setBackgroundImage:[UIImage imageNamed:bgName] forBarMetrics:UIBarMetricsDefault];
// 设置标题文字颜色
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:16];
[navBar setTitleTextAttributes:attrs];
//设置BarButtonItem的主题
UIBarButtonItem *item=[UIBarButtonItem appearance];
//设置文字颜色
NSMutableDictionary *itemAttrs=[NSMutableDictionary dictionary];
itemAttrs[NSFontAttributeName]=[UIFont systemFontOfSize:14];
itemAttrs[NSForegroundColorAttributeName]=[UIColor whiteColor];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
if (!iOS7) {
//设置按钮背景
[item setBackgroundImage:[UIImage imageNamed:@"NavButton"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[item setBackgroundImage:[UIImage imageNamed:@"NavButtonPressed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
//设置返回按钮的背景
[item setBackButtonBackgroundImage:[UIImage imageNamed:@"NavButton"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[item setBackButtonBackgroundImage:[UIImage imageNamed:@"NavButtonPressed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
}
else{
navBar.tintColor=[UIColor whiteColor];
}
}
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号