国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > iOS > 正文

關(guān)于iOS中的各種顏色設(shè)置總結(jié)大全(推薦)

2019-10-21 18:44:45
字體:
供稿:網(wǎng)友

前言

最近因為工作的原因,在做界面的時候,有時會忘記某種控件的顏色怎么設(shè)置,需要去網(wǎng)上進行搜索,所以寫下這篇文章。

一方面是收藏起來自己查閱,一方面是分享給大家。目標(biāo)是有了這篇文章,不用再去搜索和顏色設(shè)置有關(guān)的內(nèi)容。 話不多說了,來一起看看詳細的介紹吧。

下面進入正題

導(dǎo)航欄

/* 全局設(shè)置 */// 標(biāo)題顏色// 如果需要設(shè)置字體就在字典中加入 [UIFont fontWithName:@"Hiragino Sans GB" size:14][[UINavigationBar appearance] setTitleTextAttributes:  @{NSForegroundColorAttributeName:[UIColor whiteColor]}];// 導(dǎo)航欄背景顏色[[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];// 導(dǎo)航欄返回按鈕、自定義UIBarButtonItem顏色[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
/* 單獨設(shè)置 */// 導(dǎo)航欄標(biāo)題顏色self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};// 導(dǎo)航欄背景顏色self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];// 導(dǎo)航欄返回按鈕、自定義UIBarButtonItem顏色self.navigationController.navigationBar.tintColor = [UIColor blackColor];

狀態(tài)欄

進入 Targets -> General -> Status Bar Style,可以設(shè)置 黑色(默認) 和 白色。

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

如果需要精確控制不同頁面的顏色,還是需要代碼設(shè)置。

首先給 info.plist 加上這句話

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

// View controller-based status bar appearance// 加入這個參數(shù),我們前面方法的設(shè)置就會失效// 接下來就可以使用代碼進行設(shè)置了/* 全局設(shè)置 */[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;/* 單獨設(shè)置 */- (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent;}// 細心的朋友讀者可能會疑問,為什么這次不能用self.navigationController.preferredStatusBarStyle = UIStatusBarStyleLightContent;

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

答案很簡單,仔細看報錯就知道這是一個 readonly 的屬性,所有我們直接重寫他的 set 方法。

TabBar

/* 全局設(shè)置 */// TabBar背景顏色[UITabBar appearance].barTintColor = [UIColor whiteColor];/* 單獨設(shè)置 */// TabBar背景顏色self.tabBarController.tabBar.barTintColor = [UIColor whiteColor];

TabBar圖標(biāo)顏色

不用寫亂七八糟的代碼,直接到 Assets.xcassets 里把圖片的屬性 Render 設(shè)置為 Original Image 就可以讓顏色按照圖片的來,而不會選中變藍了。

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

Button

// 字體顏色// 有人可能會誤用這兩個錯誤的方法// 錯誤1:[button.titleLabel setTextColor:[UIColorblackColor]];// 錯誤2:button.titleLabel.textColor = [UIColor redColor];// 正確[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];// 邊框顏色// 默認沒有邊框,第一行是設(shè)置線條,第二行重點在于layer的顏色要用CGColorbutton.layer.borderWidth = 2.0;button.layer.borderColor = [UIColor blackColor].CGColor;

TextField

// placeholder顏色設(shè)置textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"placeHoldtext" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}]; 

AttributedString

// 初始化NSMutableAttributedStringNSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Using NSAttributed String"];// 顏色設(shè)置[str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,5)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,12)];[str addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(19,6)];// 字體設(shè)置[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Arial-BoldItalicMT" size:30.0] range:NSMakeRange(0, 5)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:30.0] range:NSMakeRange(6, 12)];[str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:30.0] range:NSMakeRange(19, 6)];// 把AttributedString賦值給LabelattrLabel.attributedText = str;

通用部分

// 字體顏色 適用于Label、TextField、TextView等label.textColor = [UIColor whiteColor];textField.textColor = [UIColor yellowColor];textView.textColor = [UIColor yellowColor];// 背景顏色 基本都使用someView.backgroundColor = [UIColor whiteColor];

工具

系統(tǒng)自帶的測色工具,位置在 應(yīng)用程序 -> 實用工具( Launchpad 里叫其他) -> 數(shù)碼測色計

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

使用方法:

打開后指向你想測色的地方即可顯示他的 RGB 色,以這個 Switch 舉個例子。

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

我們設(shè)置完rgb色后和你想要的略有差別。這里提供一個解決辦法。設(shè)置顏色的時候,點擊右邊的小齒輪,選擇 sRGB。

ios,設(shè)置導(dǎo)航欄顏色,ios設(shè)置狀態(tài)欄顏色,設(shè)置tabbar顏色

幾種常用的列舉的差不多了。不完整的地方大家可以提出來,我會對這個文章進行更新。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網(wǎng)的支持。


注:相關(guān)教程知識閱讀請移步到IOS開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 苏尼特右旗| 高要市| 寿阳县| 河东区| 台湾省| 綦江县| 荥阳市| 玛多县| 巴林右旗| 麻城市| 宁波市| 万载县| 承德县| 额尔古纳市| 库尔勒市| 昌图县| 泗洪县| 丽水市| 万全县| 台山市| 浑源县| 田东县| 泊头市| 潢川县| 波密县| 景德镇市| 舟曲县| 阿鲁科尔沁旗| 沙雅县| 阿瓦提县| 双牌县| 淅川县| 巴南区| 浏阳市| 蛟河市| 阳东县| 榆林市| 宁海县| 逊克县| 上高县| 阿克|