在AppDelegate文件中實現的方法有:
app
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptionsspa
{code
[self customNavigationBar];orm
[self customTabBar];it
return YES;io
}sed
//美化TabBarselect
-(void)customTabBar{方法
UIEdgeInsets standardEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);im
// 整個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;
}