通過(guò)appearance設(shè)置app主題

背景

最近在看開(kāi)源中國(guó)的源代碼,里面有一些自己不熟悉的知識(shí),記錄下來(lái)最為總結(jié)

參考資料

oschina源碼
http://git.oschina.net/oschina/iphone-app
TintColor解析
http://blog.kingiol.com/blog/2014/01/09/ios7-day-by-day-day6-tint-color/

oschina源碼分析

    //再plist文件中設(shè)置View controller-based status bar appearance 為 NO才能起效
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    //導(dǎo)航條上標(biāo)題的顏色
    NSDictionary *navbarTitleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    [[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
    
    //導(dǎo)航條上UIBarButtonItem顏色
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
    
    //TabBar選中圖標(biāo)的顏色,默認(rèn)是藍(lán)色
    [[UITabBar appearance] setTintColor:[UIColor colorWithHex:0x15A230]];
    //TabBarItem選中的顏色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x15A230]} forState:UIControlStateSelected];
    
    //導(dǎo)航條的背景顏色
    [[UINavigationBar appearance] setBarTintColor:[UIColor navigationbarColor]];
    
    //TabBar的背景顏色
    [[UITabBar appearance] setBarTintColor:[UIColor titleBarColor]];
    
    [UISearchBar appearance].tintColor = [UIColor redColor];
    //當(dāng)某個(gè)class被包含在另外一個(gè)class內(nèi)時(shí),才修改外觀。
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setCornerRadius:14.0];
    [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setAlpha:0.6];
    
    
    UIPageControl *pageControl = [UIPageControl appearance];
    pageControl.pageIndicatorTintColor = [UIColor colorWithHex:0xDCDCDC];
    pageControl.currentPageIndicatorTintColor = [UIColor grayColor];
    
    [[UITextField appearance] setTintColor:[UIColor nameColor]];
    [[UITextView appearance]  setTintColor:[UIColor nameColor]];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容