forked from sahin/mobileplayer-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWatermarkViewController.swift
61 lines (56 loc) · 2.24 KB
/
WatermarkViewController.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
//
// WatermarkViewController.swift
// MobilePlayer
//
// Created by Baris Sencan on 9/18/15.
// Copyright © 2015 MovieLaLa. All rights reserved.
//
import UIKit
class WatermarkViewController: MobilePlayerOverlayViewController {
let config: WatermarkConfig
let watermarkImageView = UIImageView(frame: CGRectZero)
init(config: WatermarkConfig) {
self.config = config
super.init(nibName: nil, bundle: nil)
watermarkImageView.image = config.image
view.addSubview(watermarkImageView)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let size = view.frame.size
let watermarkSize = watermarkImageView.image?.size ?? CGSizeZero
watermarkImageView.frame.size = watermarkSize
switch config.position {
case .Center:
watermarkImageView.frame.origin.x = (size.width - watermarkSize.width) / 2
watermarkImageView.frame.origin.y = (size.height - watermarkSize.height) / 2
case .Top:
watermarkImageView.frame.origin.x = (size.width - watermarkSize.width) / 2
watermarkImageView.frame.origin.y = 8
case .TopRight:
watermarkImageView.frame.origin.x = size.width - watermarkSize.width - 8
watermarkImageView.frame.origin.y = 8
case .Right:
watermarkImageView.frame.origin.x = size.width - watermarkSize.width - 8
watermarkImageView.frame.origin.y = (size.height - watermarkSize.height) / 2
case .BottomRight:
watermarkImageView.frame.origin.x = size.width - watermarkSize.width - 8
watermarkImageView.frame.origin.y = size.height - watermarkSize.height - 8
case .Bottom:
watermarkImageView.frame.origin.x = (size.width - watermarkSize.width) / 2
watermarkImageView.frame.origin.y = size.height - watermarkSize.height - 8
case .BottomLeft:
watermarkImageView.frame.origin.x = 8
watermarkImageView.frame.origin.y = size.height - watermarkSize.height - 8
case .Left:
watermarkImageView.frame.origin.x = 8
watermarkImageView.frame.origin.y = (size.height - watermarkSize.height) / 2
case .TopLeft:
watermarkImageView.frame.origin.x = 8
watermarkImageView.frame.origin.y = 8
}
}
}