• 设置导航栏主题+iOS6 & iOS7 适配


     1 /**
     2  *  设置导航栏按钮主题
     3  */
     4 + (void)setupBarButtonItemTheme
     5 {
     6     UIBarButtonItem *item = [UIBarButtonItem appearance];
     7     
     8     // 设置背景
     9     if (!iOS7) {
    10         [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    11         [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_pushed"] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
    12         [item setBackgroundImage:[UIImage imageWithName:@"navigationbar_button_background_disable"] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
    13     }
    14     
    15     // 设置文字属性
    16     NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    17     textAttrs[UITextAttributeTextColor] = iOS7 ? [UIColor orangeColor] : [UIColor grayColor];
    18     textAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
    19     textAttrs[UITextAttributeFont] = [UIFont systemFontOfSize:iOS7 ? 14 : 12];
    20     [item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    21     [item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
    22 }
    23 
    24 /**
    25  *  设置导航栏主题
    26  */
    27 + (void)setupNavBarTheme
    28 {
    29     // 取出appearance对象
    30     UINavigationBar *navBar = [UINavigationBar appearance];
    31     
    32     // 设置背景
    33     if (!iOS7) {
    34         [navBar setBackgroundImage:[UIImage imageWithName:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault];
    35         [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
    36     }
    37     
    38     // 设置标题属性
    39     NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    40     textAttrs[UITextAttributeTextColor] = [UIColor blackColor];
    41     textAttrs[UITextAttributeTextShadowOffset] = [NSValue valueWithUIOffset:UIOffsetZero];
    42     textAttrs[UITextAttributeFont] = [UIFont boldSystemFontOfSize:19];
    43     [navBar setTitleTextAttributes:textAttrs];
    44 }
  • 相关阅读:
    区块链初学者指南——五岁孩子都能理解
    推荐返利功能已上线——推荐好友下单,最高返45%
    干货|浅谈iOS端短视频SDK技术实现
    从单个系统到云翼一体化支撑,京东云DevOps推进中的一波三折
    体验京东云 Serverless+AI 人脸属性识别
    沙龙报名 | 云时代的架构演进—企业上云及云原生技术落地实践
    2020年9大顶级Java框架
    字符串函数
    linux添加用户
    unix/linux下线程私有数据实现原理及使用方法
  • 原文地址:https://www.cnblogs.com/qq449832375/p/4678775.html
Copyright © 2020-2023  润新知