zoukankan      html  css  js  c++  java
  • 设置导航栏主题+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 }
  • 相关阅读:
    8.9_java_35
    8.8_java_34
    8.7_java_33
    8.6_java_32
    8.5_java_31
    8.4_java_30
    8.3_java_29
    2020年春季学期《软件工程》教学总结
    json的标准格式
    详解 【Vue】 生命周期
  • 原文地址:https://www.cnblogs.com/qq449832375/p/4678775.html
Copyright © 2011-2022 走看看