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

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

}









转载于:https://my.oschina.net/iOSBoyJack/blog/499715

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值