码迷,mamicode.com
首页 > 其他好文 > 详细

Navigation Bar和TabBar的美化常用方法整理,后面会补充

时间:2015-08-31 19:53:34      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

在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;

}









Navigation Bar和TabBar的美化常用方法整理,后面会补充

标签:

原文地址:http://my.oschina.net/u/2447084/blog/499715

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!