forked from Ramotion/reel-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGradientView.swift
59 lines (45 loc) · 1.32 KB
/
GradientView.swift
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
//
// ContainerView.swift
// RAMReel
//
// Created by Mikhail Stepkin on 4/23/15.
// Copyright (c) 2015 Ramotion. All rights reserved.
//
import UIKit
import QuartzCore
class GradientView: UIView {
var gradientLayer: CAGradientLayer!
var listBackgroundColor: UIColor? {
didSet {
updateGradient()
}
}
func updateGradient() {
let color = listBackgroundColor ?? UIColor.white
let white = color.withAlphaComponent(1.0).cgColor
let clear = color.withAlphaComponent(0.0).cgColor
gradientLayer.colors = [clear, white, clear]
}
func setupGradientLayer() {
gradientLayer = CAGradientLayer()
gradientLayer.frame = self.bounds
updateGradient()
self.layer.insertSublayer(gradientLayer, at: 0)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupGradientLayer()
}
override init(frame: CGRect) {
super.init(frame: frame)
setupGradientLayer()
}
override func layoutSubviews() {
super.layoutSubviews()
gradientLayer.frame = self.bounds
gradientLayer.setNeedsDisplay()
}
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
return false
}
}