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

背景

最近在看開源中國的源代碼,里面有一些自己不熟悉的知識,記錄下來最為總結(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)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容