forked from haxpor/Potatso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CurrentGroupCell.swift
73 lines (58 loc) · 2.29 KB
/
CurrentGroupCell.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
//
// CurrentGroupCell.swift
// Potatso
//
// Created by LEI on 4/13/16.
// Copyright © 2016 TouchingApp. All rights reserved.
//
import UIKit
import Cartography
import PotatsoLibrary
class CurrentGroupCell: UITableViewCell {
var switchVPN: (()->Void)?
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
contentView.addSubview(nameLabel)
contentView.addSubview(switchButton)
setupLayout()
}
func onSwitchValueChanged() {
switchVPN?()
}
func config(_ name: String?, status: Bool, switchVPN: (() -> Void)?) {
nameLabel.text = name ?? "None".localized()
switchButton.setBackgroundImage("FF6959".color.alpha(0.76).toImage(), for: UIControlState())
switchButton.addTarget(self, action: #selector(self.onSwitchValueChanged), for: .touchUpInside)
switchButton.setTitle((status ? "Disconnect" : "Connect").localized(), for: UIControlState())
switchButton.setBackgroundImage((status ? "FF6959" : "1ABC9C").color.alpha(0.76).toImage(), for: UIControlState())
self.switchVPN = switchVPN
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupLayout() {
constrain(nameLabel, switchButton, contentView) { nameLabel, switchButton, superView in
nameLabel.leading == superView.leading + 20
nameLabel.centerY == superView.centerY
nameLabel.trailing == switchButton.leading - 15
switchButton.centerY == superView.centerY
switchButton.trailing == superView.trailing - 20
switchButton.width == 70
switchButton.height == 27
}
}
lazy var nameLabel: UILabel = {
let v = UILabel()
v.font = UIFont.boldSystemFont(ofSize: 17)
v.textColor = UIColor.init(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
return v
}()
lazy var switchButton: UIButton = {
let v = UIButton(type: .custom)
v.titleLabel?.font = UIFont.systemFont(ofSize: 11)
v.layer.cornerRadius = 4
v.layer.masksToBounds = true
v.clipsToBounds = true
return v
}()
}