設置導航欄的字體顏色和背景色

在NavigationController中, initialize 方法中,
在程序運行過程中,它會在你程序中每個類調用一次initialize。這個調用的時間發生在你的類接收到消息之前,但是在它的超類接收到initialize之后。
關于initialize, 請參考 http://blog.csdn.net/ajrm0925/article/details/7431982/

+ (void)initialize
{
    /** 設置UINavigationBar */
    UINavigationBar *bar = [UINavigationBar appearance];
    
    // 設置導航欄的背景
    bar.barTintColor = [UIColor colorWithHexString:@"#0abdc8" andAlph:1];
    // 設置背景
    // [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
    
    // 設置標題文字屬性
    NSMutableDictionary *barAttrs = [NSMutableDictionary dictionary];
    if (SCREEN_WIDTH == 320) { // 3.5’設備
        barAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:18];
    } else { // 其他設備
        barAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:19];
    }
    
   // bar.tintColor = [UIColor whiteColor]; 設置導航欄字體顏色
    barAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    
    [bar setTitleTextAttributes:barAttrs];

    /** 設置UIBarButtonItem */
    UIBarButtonItem *item = [UIBarButtonItem appearance];
    
    // UIControlStateNormal
    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    normalAttrs[NSForegroundColorAttributeName] = [UIColor blackColor];
    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:17];
    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    
    // UIControlStateDisabled
    NSMutableDictionary *disabledAttrs = [NSMutableDictionary dictionary];
    disabledAttrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    [item setTitleTextAttributes:disabledAttrs forState:UIControlStateDisabled];
}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容