Last active
January 19, 2021 07:21
-
-
Save stevencurtis/b5fa9851567d42b8336ce437998b1170 to your computer and use it in GitHub Desktop.
completeLoadView
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
final class MyViewController: UIViewController { | |
override func loadView() { | |
let view = ButtonView() | |
view.button.addTarget(self, action: #selector(buttonDidTap), for: .touchDown) | |
self.view = view | |
} | |
@objc | |
private func buttonDidTap() { | |
let controller = DetailViewController() | |
present(controller, animated: true, completion: nil) | |
} | |
} | |
class ButtonView: UIView { | |
let button = UIButton(type: .custom) | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
createSubviews() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
createSubviews() | |
} | |
func createSubviews() { | |
self.backgroundColor = .green | |
button.frame = CGRect(x: 0, y: 0, width: 200, height: 20) | |
button.setTitle("Tap to go to Detail View", for: .normal) | |
button.setTitleColor(.black, for: .normal) | |
button.isUserInteractionEnabled = true | |
self.addSubview(button) | |
button.translatesAutoresizingMaskIntoConstraints = false | |
button.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true | |
button.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true | |
} | |
} | |
final class DetailViewController: UIViewController { | |
override func loadView() { | |
let view = DetailUIView() | |
view.button.addTarget(self, action: #selector(buttonDidTap), for: .touchDown) | |
self.view = view | |
} | |
@objc | |
private func buttonDidTap() { | |
dismiss(animated: true, completion: nil) | |
} | |
} | |
class DetailUIView: UIView { | |
let button = UIButton(type: .custom) | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
createSubviews() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
createSubviews() | |
} | |
func createSubviews() { | |
self.backgroundColor = .orange | |
button.frame = CGRect(x: 0, y: 0, width: 200, height: 20) | |
button.setTitle("Tap to dismiss view", for: .normal) | |
button.setTitleColor(.black, for: .normal) | |
button.isUserInteractionEnabled = true | |
self.addSubview(button) | |
button.translatesAutoresizingMaskIntoConstraints = false | |
button.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true | |
button.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true | |
self.addSubview(button) | |
} | |
} | |
// set the view and indefiniteexecution | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
PlaygroundPage.current.liveView = MyViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment