在AppDelegate文件中实现的方法有:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customNavigationBar];
[self customTabBar];
return YES;
}
//美化TabBar
-(void)customTabBar{
UIEdgeInsets standardEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
// 整个tabBar的背景图
[[UITabBar appearance] setBackgroundImage:[[UIImage imageNamed:@"tabbar_back"] resizableImageWithCapInsets:standardEdgeInsets resizingMode:UIImageResizingModeStretch]];
//设置tab bar上每一个项被选中时的背景图
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected_back"]];
//设置tab bar item上文字的位置 大小 颜色
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -1)];
[[UITabBarItem appearance]setTitleTextAttributes:@{
NSForegroundColorAttributeName:[UIColor lightGrayColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:12]
} forState:UIControlStateNormal];
[[UITabBarItem appearance]setTitleTextAttributes:@{
NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:12]
} forState:UIControlStateSelected];
}
//美化导航栏
-(void)customNavigationBar{
//设置背景色
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
//设置有导航条时,状态栏的文字颜色
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
//设置导航条的背景图
//[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavigationBarDefault"] forBarMetrics:UIBarMetricsDefault];
//设置左右按钮上的文字颜色
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//设置返回按钮中出现的箭头样式
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn"]];
//设置中间的title的文字样式
//设置阴影 颜色 偏移量
NSShadow *shadow = [[NSShadow alloc]init];
shadow.shadowColor = [UIColor redColor];
shadow.shadowOffset = CGSizeMake(0, 1);
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:shadow,NSShadowAttributeName,[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21],NSFontAttributeName,nil];
[[UINavigationBar appearance] setTitleTextAttributes:dictionary];
}
//在控制器中要实现的方法有
- (id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self){
[self.navigationController.tabBarItem setImage:[UIImage imageNamed:@"tabbar_item_my_music"]];
[self.navigationController.tabBarItem setSelectedImage:[[UIImage imageNamed:@"tabbar_item_my_music_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] ];
}
return self;
}