-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChannelCollectionPageView.swift
74 lines (63 loc) · 2.8 KB
/
ChannelCollectionPageView.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// ChannelCollectionPageView.swift
// SmartStream
//
// Created by Marc Anderson on 3/10/16.
// Copyright © 2016 SmartStream. All rights reserved.
//
import UIKit
protocol ChannelCollectionPageViewDelegate: class {
func channelCollectionPageView(sender: ChannelCollectionPageView, didPlayChannel channel: Channel)
}
class ChannelCollectionPageView: UIView {
@IBOutlet var contentView: UIView!
@IBOutlet weak var pageImageView: UIImageView!
@IBOutlet weak var channelNameContainerView: UIView!
@IBOutlet weak var channelNameLabel: UILabel!
var channel: Channel! {
didSet {
channelNameLabel.text = channel.title
if let coverURL = channel.curated?.cover_url {
let request = NSURLRequest(URL: NSURL(string: coverURL)!)
pageImageView.setImageWithURLRequest(request, placeholderImage: UIImage(named: "placeholder"), success: { (request: NSURLRequest, response: NSHTTPURLResponse?, image: UIImage) -> Void in
self.pageImageView.image = image
self.pageImageView.layer.opacity = 0
UIView.transitionWithView(self.pageImageView, duration: 0.3, options: UIViewAnimationOptions.CurveEaseIn, animations: { () -> Void in
self.pageImageView.layer.opacity = 1
}, completion: { (bool: Bool) -> Void in
//
})
}, failure: { (request: NSURLRequest, response: NSHTTPURLResponse?, error: NSError) -> Void in
//
})
}
}
}
weak var delegate: ChannelCollectionPageViewDelegate?
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
initSubviews()
}
override init(frame: CGRect) {
super.init(frame: frame)
initSubviews()
}
func initSubviews() {
// standard initialization logic
let nib = UINib(nibName: "ChannelCollectionPageView", bundle: nil)
nib.instantiateWithOwner(self, options: nil)
contentView.frame = bounds
addSubview(contentView)
// Theming
pageImageView.backgroundColor = UIColor.clearColor()
channelNameContainerView.layer.cornerRadius = 4.0
channelNameContainerView.clipsToBounds = true
channelNameContainerView.backgroundColor = Theme.Colors.DarkBackgroundColor.color.colorWithAlphaComponent(0.7)
channelNameContainerView.layer.borderColor = Theme.Colors.LightBackgroundColor.color.CGColor
channelNameContainerView.layer.borderWidth = 1.0
channelNameLabel.textColor = Theme.Colors.HighlightColor.color
}
@IBAction func onTapChannel(sender: UITapGestureRecognizer) {
delegate?.channelCollectionPageView(self, didPlayChannel: channel)
}
}