Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created June 12, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevencurtis/3a4e713fc3e0cf7a45548dded7976955 to your computer and use it in GitHub Desktop.
Save stevencurtis/3a4e713fc3e0cf7a45548dded7976955 to your computer and use it in GitHub Desktop.
InitialView
final class InitialView: UIView {
let traverseButton = UIButton(type: .custom)
let networkButton = UIButton(type: .custom)
let networkLabel = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
self.backgroundColor = .red
traverseButton.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
traverseButton.setTitle("Go to Detail", for: .normal)
traverseButton.setTitleColor(.black, for: .normal)
traverseButton.isUserInteractionEnabled = true
self.addSubview(traverseButton)
traverseButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
traverseButton.centerXAnchor.constraint(equalTo: self.centerXAnchor),
traverseButton.centerYAnchor.constraint(equalTo: self.centerYAnchor)
])
networkButton.frame = CGRect(x: 0, y: 0, width: 200, height: 100)
networkButton.setTitle("Make Network Call", for: .normal)
networkButton.setTitleColor(.black, for: .normal)
networkButton.isUserInteractionEnabled = true
self.addSubview(networkButton)
networkButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
networkButton.centerXAnchor.constraint(equalTo: self.centerXAnchor),
networkButton.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 100)
])
networkLabel.text = "No network calls made"
networkLabel.backgroundColor = .purple
self.addSubview(networkLabel)
networkLabel.translatesAutoresizingMaskIntoConstraints = false
networkLabel.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
networkLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor, constant: 200).isActive = true
networkLabel.widthAnchor.constraint(equalToConstant: 300).isActive = true
networkLabel.heightAnchor.constraint(equalToConstant: 100).isActive = true
}
func setNetworkLabel(text: String){
networkLabel.text = text
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment