Guest User

Untitled

a guest
Apr 25th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. class BaseViewController: UIViewController {
  2.  
  3. let headerView: UIView = {
  4. let view = UIView()
  5. view.backgroundColor = UIColor.green
  6. return view
  7. }()
  8.  
  9. func addHeader() {
  10. view.addSubview(headerView)
  11. // then anchor it to top
  12. }
  13.  
  14. }
  15.  
  16. class ScrollViewController: UIViewController {
  17.  
  18. let scrollView: UIScrollView = {
  19. let view = UIScrollView()
  20. view.backgroundColor = UIColor.green
  21. return view
  22. }()
  23.  
  24. func addScrollView() {
  25. view.addSubview(scrollView)
  26. // then anchor it to top
  27. }
  28.  
  29. }
  30.  
  31. class HomeViewController: ScrollViewController, BaseViewController {
  32.  
  33. override viewDidLoad() {
  34. super.viewDidLoad()
  35.  
  36. addScrollView()
  37. addHeaderView()
  38.  
  39. let view = UIView()
  40. //anchor view to bottom of the header
  41. }
  42. }
  43.  
  44. protocol HeaderProtocol {
  45. func addHeader()
  46. }
  47.  
  48. extension HeaderProtocol where Self: UIViewController {
  49. func addHeader() {
  50. let headerView = UIView()
  51. headerView.backgroundColor = UIColor.green
  52. view.addSubview(headerView)
  53. // then anchor it to top
  54. }
  55. }
  56.  
  57. protocol ScrollViewProtocol {
  58. func addScrollView()
  59. }
  60.  
  61. extension ScrollViewProtocol where Self: UIViewController {
  62. func addScrollView() {
  63. let scrollView = UIScrollView()
  64. scrollView.backgroundColor = UIColor.green
  65. view.addSubview(scrollView)
  66. // then anchor it to top
  67. }
  68. }
  69.  
  70. class HomeViewController: ScrollViewProtocol, HeaderProtocol {
  71. override func viewDidLoad() {
  72. super.viewDidLoad()
  73.  
  74. addScrollView()
  75. addHeaderView()
  76. }
  77. }
Add Comment
Please, Sign In to add comment