Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. import RxSwift
  2. import RxCocoa
  3. import Action
  4.  
  5. final class ViewController: UIViewController {
  6.  
  7. // UI Elements
  8. fileprivate var aButton = ViewController._aButton()
  9. fileprivate var anotherButton = ViewController._aButton()
  10. fileprivate let logo = ViewController._logo()
  11.  
  12. // Data Bindings
  13. private let disposeBag = DisposeBag()
  14. var viewModel: ControllerViewModelType!
  15.  
  16. func bindViewModel() {
  17.  
  18. aButton.rx.tap
  19. .bind(to: viewModel.actions.pushFirstScreen.inputs)
  20. .disposed(by: disposeBag)
  21.  
  22. anotherButton.rx.action = viewModel.actions.pushSecondScreen
  23. }
  24.  
  25. // Controller Life Cycle
  26. override func viewDidLoad() {
  27. super.viewDidLoad()
  28.  
  29. bindViewModel()
  30. setupViews()
  31. }
  32.  
  33. override func viewWillAppear(_ animated: Bool) {
  34. super.viewWillAppear(animated)
  35.  
  36. UIApplication.shared.isStatusBarHidden = true
  37. navigationController?.navigationBar?.isHidden = true
  38. }
  39. }
  40.  
  41. // MARK: Helpers
  42.  
  43.  
  44. // MARK: UI Elements
  45. extension ViewController {
  46.  
  47. fileprivate func setupViews() {
  48.  
  49. view.backgroundColor = .blue
  50.  
  51. // MARK: Logo setup
  52. view.addSubview(logo)
  53. logo.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
  54. logo.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -view.bounds.size.height / 15).isActive = true
  55. logo.widthAnchor.constraint(equalTo: view.widthAnchor, multiplier: 1/1.7).isActive = true
  56. logo.heightAnchor.constraint(equalTo: logo.widthAnchor).isActive = true
  57.  
  58. // MARK: aButton setup
  59. aButton.setTitle("Hello", for: .normal)
  60. view.addSubview(aButton)
  61. aButton.leftAnchor.constraint(equalTo: view.leftAnchor, constant: view.bounds.size.height / 20).isActive = true
  62. aButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -view.bounds.size.height / 16).isActive = true
  63. aButton.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 1/5).isActive = true
  64. aButton.widthAnchor.constraint(equalTo: aButton.heightAnchor, multiplier: 1/2).isActive = true
  65.  
  66. // MARK: anotherButton setup
  67. anotherButton.setTitle("Hi", for: .normal)
  68. view.addSubview(anotherButton)
  69. anotherButton.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -view.bounds.size.height / 20).isActive = true
  70. anotherButton.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -view.bounds.size.height / 16).isActive = true
  71. anotherButton.heightAnchor.constraint(equalTo: aButton.heightAnchor).isActive = true
  72. anotherButton.widthAnchor.constraint(equalTo: anotherButton.heightAnchor, multiplier: 1/2).isActive = true
  73. }
  74.  
  75. class func _logo() -> UIImageView {
  76.  
  77. let iv = UIImageView()
  78.  
  79. iv.contentMode = .scaleAspectFit
  80. iv.image = UIImage(named: "logo.png")
  81. iv.translatesAutoresizingMaskIntoConstraints = false
  82. return iv
  83. }
  84.  
  85. class func _aButton() -> UIButton {
  86.  
  87. let button = UIButton(type: .custom)
  88.  
  89. button.imageView?.contentMode = .scaleAspectFit
  90. button.translatesAutoresizingMaskIntoConstraints = false
  91. return button
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement