美文网首页
全局设置NavigationBar样式 2019-06-26

全局设置NavigationBar样式 2019-06-26

作者: 上官凌玉 | 来源:发表于2019-06-26 12:06 被阅读0次

    建议写进UINavigationBar的Category便于不同项目复用

    [[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]]; // 隐藏底部线条
    
        [UINavigationBar appearance].titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]}; // 设置title 颜色
    
        [UINavigationBar appearance].backIndicatorImage = 
        [UINavigationBar appearance].backIndicatorTransitionMaskImage =
        [UIImage templateImageNamed:@"nav_bar_back_icon_white"];
    
        [[UINavigationBar appearance] setBarTintColor:MMA_BLACK(1)];
        [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
        // hide title of back button
        [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                             forBarMetrics:UIBarMetricsDefault];
    
        NSShadow *clearShadow = [[NSShadow alloc] init];
        clearShadow.shadowColor = [UIColor clearColor];
        clearShadow.shadowOffset = CGSizeMake(0, 0);
     
        UIColor *normalTitleColor = [UIColor whiteColor];
        UIColor *highlightedTitleColor = [UIColor whiteColor];
        [[UIBarButtonItem appearance] setTitleTextAttributes:@{
                                                               NSForegroundColorAttributeName : normalTitleColor,
                                                               NSShadowAttributeName : clearShadow
                                                               } forState:UIControlStateNormal];
        [[UIBarButtonItem appearance] setTitleTextAttributes:@{
                                                               NSForegroundColorAttributeName : highlightedTitleColor,
                                                               NSShadowAttributeName : clearShadow
                                                               } forState:UIControlStateHighlighted];
        [[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
        [[UIToolbar appearance] setBarTintColor:[UIColor whiteColor]]; 
     
    

    相关文章

      网友评论

          本文标题:全局设置NavigationBar样式 2019-06-26

          本文链接:https://www.haomeiwen.com/subject/gvtccctx.html