[Xcode10 实际操作]七、文件与数据-(19)颜色集(Color Set)的使用

本文将演示颜色集合的使用。

使用颜色集合可以很方便地创建应用程序的主题色,并且可以方便的对主题颜色进行更换。

要使用颜色集功能,需要设置项目的部署(Deployment)版本号。

【Deployment Target】:选择11.0以上的选项。

接着打开资源文件夹,在资源文件夹中创建颜色集合。

【Assets.xcassets】->【+】->【New Color Set】->

点击修改颜色的默认名称:BackgroundColor

->打开属性设置面板->点击刚才新建的图标,切换至颜色设置面板。

颜色集合的默认颜色为白色,可以修改红、绿、蓝颜色通道的数值

->使用相同的方式,创建第二个颜色集合。

【Assets.xcassets】->【+】->【New Color Set】->

点击修改颜色的默认名称:ForegroundColor

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

 1 import UIKit
 2
 3 class ViewController: UIViewController {
 4
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8
 9         //创建一个标签对象,它的显示区域和根视图相同,
10         let lbl = UILabel(frame: self.view.frame)
11
12         //添加一个版本兼容性的判断语句
13         if #available(iOS 11.0, *)
14         {
15             //分别设置两个颜色集合
16             //作为标签对象的背景颜色
17             lbl.backgroundColor = UIColor(named: "BackgroundColor")
18             //作为标签对象的文字颜色
19             lbl.textColor = UIColor(named:"ForegroundColor")
20         }
21
22         //设置标签对象的文字内容
23         lbl.text = "https://www.cnblogs.com/strengthen/"
24         //设置标签对象的文字对齐方式
25         lbl.textAlignment = .center
26
27         //将标签对象添加到当前视图控制器的根视图
28         self.view.addSubview(lbl)
29     }
30
31     override func didReceiveMemoryWarning() {
32         super.didReceiveMemoryWarning()
33         // Dispose of any resources that can be recreated.
34     }
35 }

颜色背景也可以应用在故事版中,在故事版中设置根视图的背景颜色。

首先清除标签对象的背景颜色。

使用快捷键【Command】+【/】注释标签背景颜色:

//lbl.backgroundColor = UIColor(named: "BackgroundColor")

接着打开并编辑故事版文件【main.storyboard】

选择当前视图控制器的根视图。

打开右侧的属性设置面板,设置:

【Background】:在颜色面板中,显示了刚自定义的两个颜色集合。选择其中一个。

原文地址:https://www.cnblogs.com/strengthen/p/10052190.html

时间: 2024-08-30 13:03:17

[Xcode10 实际操作]七、文件与数据-(19)颜色集(Color Set)的使用的相关文章

python操作txt文件中数据教程[1]-使用python读写txt文件

python操作txt文件中数据教程[1]-使用python读写txt文件 觉得有用的话,欢迎一起讨论相互学习~Follow Me 原始txt文件 程序实现后结果 程序实现 filename = './test/test.txt' contents = [] DNA_sequence = [] # 打开文本并将所有内容存入contents中 with open(filename, 'r') as f: for line in f.readlines(): contents.append(line

[Xcode10 实际操作]七、文件与数据-(14)数据持久化存储框架CoreData的使用:删除CoreData中的数据

本文将演示如何删除数据持久化对象. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 //引入数据持久化存储框架[CoreData] 3 import CoreData 4 5 class ViewController: UIViewController { 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 // Do any additional setup a

[Xcode10 实际操作]七、文件与数据-(1)获取程序沙箱结构中常用的几个目录

本文将演示如何获取程序沙箱结构中,常见的几个目录. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically fro

[Xcode10 实际操作]七、文件与数据-(4 )遍历文件夹中的文件

本文将演示如何遍历文件夹下的内容. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib.

[Xcode10 实际操作]七、文件与数据-(3)创建文本文件、属性列表文件、图片文件

本文将演示如何创建各种类型的文件. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from a nib.

[Xcode10 实际操作]七、文件与数据-(9)编码创建Plist文件(属性列表文件)

本文将演示如何通过编码的方式,创建属性列表文件. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] 1 import UIKit 2 3 class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 // Do any additional setup after loading the view, typically from

[Xcode10 实际操作]七、文件与数据-(16)解析XML文档

本文将演示如何解析XML文档. 项目中已添加一份XML文档:worker.xml 1 <?xml version="1.0" encoding="UTF-8" ?> 2 <workers> 3 <worker id='1'> 4 <name>Jerry</name> 5 <age>35</age> 6 <salary>25600</salary> 7 <

对数据文件的操作和文件流

一直到现在,我还是用键盘对程序进行输入,但是实际情况中大部分是对文件进行读取和输出,今天就学习一下对文件的输入输出  . 根据文件对数据的组织形式 , 可分为ascll文件和二进制文件    "ascll"文件 又称 文本文件或字符文件  .     文件流 不是若干个文件组成的流  而是以  文件流输入输出  若要对文件进行输入输出  ,  若要对文件进行输入输出  . 就必须通过文件流 来实现  . 现有  三个 用于文件操作的文件类  . ifstream 类 他是从istrea

七牛大数据平台的演进与大数据分析实践--转

原文地址:http://www.infoq.com/cn/articles/qiniu-big-data-platform-evolution-and-analysis?utm_source=infoq&utm_medium=popular_widget&utm_campaign=popular_content_list&utm_content=homepage 七牛大数据平台的演进与大数据分析实践 (点击放大图像) 图 1 大数据生态体系 看着图 1 大家可能会感到熟悉,又或者会