-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
105 lines (84 loc) · 4 KB
/
ViewController.swift
File metadata and controls
105 lines (84 loc) · 4 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// ViewController.swift
// Demo
//
// Created by Mr.wu on 2020/2/18.
// Copyright © 2020 Mr.wu. All rights reserved.
//
import UIKit
import FXViewKit
class ViewController: UIViewController {
let lrView = LeftRightView<UILabel, UIButton>()
let tbView = TopBottomView<UILabel, UIButton>()
let testView = LeftRightView<LeftRightView<UILabel, UILabel>, UIButton>()
let contentView = ContentView<UIView>()
override func viewDidLoad() {
super.viewDidLoad()
lrView.backgroundColor = .systemPink
lrView.leftView.text = "left"
lrView.leftView.backgroundColor = .systemBlue
lrView.rightView.addTarget(self, action: #selector(lrViewTap), for: .touchUpInside)
lrView.rightView.backgroundColor = .green
lrView.rightView.setTitle("right", for: .normal)
lrView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(lrView)
NSLayoutConstraint.activate([
lrView.leftAnchor.constraint(equalTo: view.leftAnchor),
lrView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
lrView.heightAnchor.constraint(equalToConstant: 44),
lrView.rightAnchor.constraint(equalTo: view.rightAnchor)
])
tbView.backgroundColor = .systemPink
tbView.topView.text = "top"
tbView.topView.backgroundColor = .systemBlue
tbView.bottomView.addTarget(self, action: #selector(tbViewTap), for: .touchUpInside)
tbView.bottomView.backgroundColor = .green
tbView.bottomView.setTitle("bottom", for: .normal)
tbView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(tbView)
NSLayoutConstraint.activate([
tbView.topAnchor.constraint(equalTo: view.topAnchor),
tbView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
tbView.widthAnchor.constraint(equalToConstant: 60),
tbView.bottomAnchor.constraint(equalTo: lrView.topAnchor)
])
testView.backgroundColor = .systemPink
testView.leftView.leftView.text = "left------"
testView.leftView.backgroundColor = .systemBlue
testView.leftView.rightView.backgroundColor = .green
testView.leftView.rightView.text = "right"
testView.rightView.setTitle("???????????", for: .normal)
testView.rightView.backgroundColor = .brown
testView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(testView)
NSLayoutConstraint.activate([
testView.leftAnchor.constraint(equalTo: view.leftAnchor),
testView.topAnchor.constraint(equalTo: lrView.bottomAnchor),
testView.heightAnchor.constraint(equalToConstant: 44),
testView.rightAnchor.constraint(equalTo: view.rightAnchor)
])
contentView.edges = UIEdgeInsets(top: 5, left: 5, bottom: -5, right: -5)
contentView.backgroundColor = .systemRed
contentView.contentView.backgroundColor = .green
contentView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(contentView)
NSLayoutConstraint.activate([
contentView.leftAnchor.constraint(equalTo: view.leftAnchor),
contentView.topAnchor.constraint(equalTo: view.topAnchor),
contentView.widthAnchor.constraint(equalToConstant: 40),
contentView.heightAnchor.constraint(equalToConstant: 40)
])
}
@objc func lrViewTap() {
lrView.edges.top = CGFloat(arc4random() % 10)
lrView.edges.left = CGFloat(arc4random() % 10)
lrView.edges.right = CGFloat(arc4random() % 10)
lrView.edges.bottom = CGFloat(arc4random() % 10)
}
@objc func tbViewTap() {
tbView.edges.top = CGFloat(arc4random() % 10)
tbView.edges.left = CGFloat(arc4random() % 10)
tbView.edges.right = CGFloat(arc4random() % 10)
tbView.edges.bottom = CGFloat(arc4random() % 10)
}
}