Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RxSwift
- import RxCocoa
- import Action
- final class ViewController: UIViewController {
- // UI Elements
- fileprivate var aButton = ViewController._aButton()
- fileprivate var anotherButton = ViewController._aButton()
- fileprivate let logo = ViewController._logo()
- // Data Bindings
- private let disposeBag = DisposeBag()
- var viewModel: ControllerViewModelType!
- func bindViewModel() {
- aButton.rx.tap
- .bind(to: viewModel.actions.pushFirstScreen.inputs)
- .disposed(by: disposeBag)
- anotherButton.rx.action = viewModel.actions.pushSecondScreen
- }
- // Controller Life Cycle
- override func viewDidLoad() {
- super.viewDidLoad()
- bindViewModel()
- setupViews()
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- UIApplication.shared.isStatusBarHidden = true
- navigationController?.navigationBar?.isHidden = true
- }
- }
- // MARK: Helpers
- // MARK: UI Elements
- extension ViewController {
- fileprivate func setupViews() {
- view.backgroundColor = .blue
- // MARK: Logo setup
- view.addSubview(logo)
- logo.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
- logo.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -view.bounds.size.height / 15).isActive = true
- logo.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1/1.7).isActive = true
- logo.heightAnchor.constraint(equalTo: logo.widthAnchor).isActive = true
- // MARK: aButton setup
- aButton.setTitle("Hello", for: .normal)
- view.addSubview(aButton)
- aButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: view.bounds.size.height / 20).isActive = true
- aButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -view.bounds.size.height / 16).isActive = true
- aButton.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 1/5).isActive = true
- aButton.widthAnchor.constraint(equalTo: aButton.heightAnchor, multiplier: 1/2).isActive = true
- // MARK: anotherButton setup
- anotherButton.setTitle("Hi", for: .normal)
- view.addSubview(anotherButton)
- anotherButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -view.bounds.size.height / 20).isActive = true
- anotherButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -view.bounds.size.height / 16).isActive = true
- anotherButton.heightAnchor.constraint(equalTo: aButton.heightAnchor).isActive = true
- anotherButton.widthAnchor.constraint(equalTo: anotherButton.heightAnchor, multiplier: 1/2).isActive = true
- }
- class func _logo() -> UIImageView {
- let iv = UIImageView()
- iv.contentMode = .scaleAspectFit
- iv.image = UIImage(named: "logo.png")
- iv.translatesAutoresizingMaskIntoConstraints = false
- return iv
- }
- class func _aButton() -> UIButton {
- let button = UIButton(type: .custom)
- button.imageView?.contentMode = .scaleAspectFit
- button.translatesAutoresizingMaskIntoConstraints = false
- return button
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement