forked from bestswifter/MySampleCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
53 lines (40 loc) · 1.46 KB
/
ViewController.swift
File metadata and controls
53 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// ViewController.swift
// KTColor
//
// Created by 张星宇 on 16/2/14.
// Copyright © 2016年 zxy. All rights reserved.
//
import UIKit
/// 通过继承实现字符串字面量创建UIColor对象
class KtColor: UIColor, StringLiteralConvertible {
required init(stringLiteral value: String) {
super.init(red: 0.5, green: 0.8, blue: 0.25, alpha: 1)
}
required convenience init(extendedGraphemeClusterLiteral value: String) {
self.init(stringLiteral: value)
}
required convenience init(unicodeScalarLiteral value: String) {
self.init(stringLiteral: value)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
required convenience init(colorLiteralRed red: Float, green: Float, blue: Float, alpha: Float) {
self.init(colorLiteralRed: red, green: green, blue: blue, alpha: alpha)
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = "224, 222, 255, 0.5".ktcolor
self.view.backgroundColor = "#DC143C".ktcolor
self.view.backgroundColor = "SkyBlue".ktcolor
self.view.backgroundColor = "224,222,255".ktcolor
self.view.backgroundColor = "224, 222, 255" as KtColor
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}