Created
October 19, 2020 19:36
-
-
Save 5SMNOONMS5/3c0e45c70bd437facbfc34b5bb729356 to your computer and use it in GitHub Desktop.
Priority
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import SnapKit_Sources | |
import PlaygroundSupport | |
final class TestView: UIView { | |
let labelPrimary: UILabel = { | |
let label = UILabel() | |
label.font = UIFont.systemFont(ofSize: 25) | |
label.textColor = .black | |
label.text = "Primary Text" | |
label.textAlignment = .center | |
return label | |
}() | |
let labelSecondary: UILabel = { | |
let label = UILabel() | |
label.font = UIFont.systemFont(ofSize: 14) | |
label.textColor = .blue | |
label.textAlignment = .center | |
return label | |
}() | |
init(secondary: String?) { | |
super.init(frame: .zero) | |
labelSecondary.text = secondary | |
addSubview(labelSecondary) | |
labelSecondary.snp.makeConstraints { (make) in | |
make.left.equalToSuperview() | |
make.right.equalToSuperview() | |
make.top.equalToSuperview() | |
} | |
addSubview(labelPrimary) | |
labelPrimary.snp.makeConstraints { (make) in | |
make.left.equalToSuperview() | |
make.right.equalToSuperview() | |
make.top.equalTo(labelSecondary.snp.bottom).priority(251) | |
make.bottom.equalToSuperview() | |
} | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
} | |
final class MyViewController: UIViewController { | |
private let view1: TestView = { | |
let view = TestView(secondary: "Secondary Text") | |
view.backgroundColor = .gray | |
return view | |
}() | |
private let view2: TestView = { | |
let view = TestView(secondary: nil) | |
view.backgroundColor = .gray | |
return view | |
}() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
setupUI() | |
} | |
/// Setup UI elements | |
private func setupUI() { | |
view1.frame = CGRect(x: 50, y: 100, width: 200, height: 50) | |
view.addSubview(view1) | |
view2.frame = CGRect(x: 50, y: 200, width: 200, height: 50) | |
view.addSubview(view2) | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(true) | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(true) | |
dump("labelPrimary => \(view2.labelPrimary.constraints)") | |
print("==============") | |
dump("labelSecondary => \(view2.labelSecondary.constraints)") | |
} | |
} | |
let vc = MyViewController() | |
let frame = CGRect(x: 0, y: 0, width: 768, height: 1024) | |
let window = UIWindow(frame: frame) | |
window.rootViewController = vc | |
window.makeKeyAndVisible() | |
PlaygroundPage.current.liveView = vc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment