-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathUIGViewController.swift
More file actions
71 lines (46 loc) · 2.24 KB
/
Copy pathUIGViewController.swift
File metadata and controls
71 lines (46 loc) · 2.24 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// "ViewController.swift
// NilColorKit
//
// Created by Peng on 10/15/14.
// Copyright (c) 2014 peng. All rights reserved.
//
import Foundation
import UIKit
import QuartzCore
class UIGViewController: UITableViewController {
typealias gradientColors = (startColor:UIColor,endColor:UIColor)
let gradients: [String:gradientColors] = [
"EmeraldWater":(UIColor.uig_emeraldWaterStartColor(),UIColor.uig_emeraldWaterEndColor()),
"LemonTwist":(UIColor.uig_lemonTwistStartColor(),UIColor.uig_lemonTwistEndColor()),
"Horizon":(UIColor.uig_horizonStartColor(),UIColor.uig_horizonEndColor()),
"RoseWater":(UIColor.uig_roseWaterStartColor(),UIColor.uig_roseWaterEndColor()),
"Frozen":(UIColor.uig_frozenStartColor(),UIColor.uig_frozenEndColor())
]
override func awakeFromNib() {
super.awakeFromNib()
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.translucent = false
self.title = "Gradients"
self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
}
// MARK: - Table View
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return gradients.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
let gradientName: String = [String](gradients.keys)[indexPath.row] as String
let startColor:UIColor = gradientColors(gradients[gradientName]!).startColor
let endColor: UIColor = gradientColors(gradients[gradientName]!).endColor
let gradient: CAGradientLayer = CAGradientLayer()
gradient.frame = cell.contentView.bounds
gradient.startPoint = CGPointMake(0.0, 0.5)
gradient.endPoint = CGPointMake(1.0, 0.5)
gradient.colors = [startColor.CGColor!, endColor.CGColor!]
cell.contentView.layer.insertSublayer(gradient, atIndex: 0);
return cell
}
}