Guest User

Untitled

a guest
Jan 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. import UIKit
  2.  
  3. class StandMapView: UIView {
  4.  
  5. var titleLabel: UILabel = UILabel()
  6. var standMapImage: UIImageView = UIImageView()
  7. var hotspotImage: UIImageView = UIImageView()
  8. var hotspotTitleLabelArray: [UILabel] = []
  9. var hotspotTextArray: [UITextView] = []
  10.  
  11. override init(frame: CGRect) {
  12. super.init(frame: frame)
  13. setupView()
  14. }
  15.  
  16. required init?(coder aDecoder: NSCoder) {
  17. fatalError("init(coder:) has not been implemented")
  18. }
  19.  
  20. func bind(standMap: StandMap, hotspots: [Hotspot]) {
  21. titleLabel.text = standMap.title
  22. standMapImage.image = UIImage(named: standMap.mapImage)
  23. hotspotImage.image = UIImage(named:standMap.hotspotImage)
  24. for hotspot in hotspots {
  25. let hotspotTitle = UILabel()
  26. let hotspotText = UITextView()
  27. hotspotTitle.text = hotspot.title
  28. hotspotText.text = hotspot.text
  29. hotspotTitleLabelArray.append(hotspotTitle)
  30. hotspotTextArray.append(hotspotText)
  31. }
  32. }
  33.  
  34. private func setupView() {
  35.  
  36. let screenWidth = UIScreen.mainScreen().bounds.width
  37. let screenHeight = UIScreen.mainScreen().bounds.height
  38. self.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
  39.  
  40. titleLabel.translatesAutoresizingMaskIntoConstraints = false
  41. standMapImage.translatesAutoresizingMaskIntoConstraints = false
  42. hotspotImage.translatesAutoresizingMaskIntoConstraints = false
  43.  
  44. self.backgroundColor = UIColor.blackColor()
  45.  
  46. titleLabel.sizeToFit()
  47.  
  48. titleLabel.frame = CGRect(x: screenWidth/2, y: 30, width: 0, height: 0)
  49. titleLabel.textAlignment = .Center
  50. titleLabel.numberOfLines = 0
  51. titleLabel.adjustsFontSizeToFitWidth = true
  52. titleLabel.textColor = UIColor.whiteColor()
  53.  
  54. addSubview(titleLabel)
  55.  
  56. }
  57.  
  58. }
  59.  
  60. import UIKit
  61.  
  62. class StandMapViewController: UIViewController {
  63.  
  64. var standMap: StandMap!
  65. var hotspots: [Hotspot] = []
  66.  
  67. override func viewDidLoad() {
  68. super.viewDidLoad()
  69.  
  70. Hotspot.all { hotspot in
  71. hotspot.forEach(self.assignHotspotVariable)
  72. }
  73.  
  74. StandMap.build {standMap in
  75. standMap.forEach(self.assignStandMapVariable)
  76. }
  77.  
  78. viewForStandMap(standMap, hotspots: hotspots)
  79.  
  80. }
  81.  
  82. private func assignStandMapVariable(standMap: StandMap) {
  83. self.standMap = standMap
  84. }
  85.  
  86. private func assignHotspotVariable(hotspot: Hotspot) {
  87. hotspots.append(hotspot)
  88. }
  89.  
  90. private func viewForStandMap(standMap: StandMap, hotspots: [Hotspot]) {
  91. let standMapView = StandMapView(frame: CGRectZero)
  92. standMapView.bind(standMap, hotspots: hotspots)
  93. view.addSubview(standMapView)
  94. }
  95. }
  96.  
  97. titleLabel.frame.origin.x = 0.0 // put your value
  98. titleLabel.frame.origin.y = 0.0 // put your value
  99. self.view.layoutIfNeeded()
  100.  
  101. private func setupView() {
  102.  
  103. titleLabel.translatesAutoresizingMaskIntoConstraints = false
  104. standMapImage.translatesAutoresizingMaskIntoConstraints = false
  105. hotspotImage.translatesAutoresizingMaskIntoConstraints = false
  106.  
  107. self.backgroundColor = UIColor.blackColor()
  108. titleLabel.textColor = UIColor.whiteColor()
  109. titleLabel.textAlignment = .Center
  110. titleLabel.numberOfLines = 0
  111. titleLabel.adjustsFontSizeToFitWidth = true
  112. addSubview(titleLabel)
  113.  
  114. titleLabel.snp_makeConstraints { make in
  115. make.topMargin.equalTo(snp_topMargin).multipliedBy(60)
  116. make.centerX.equalTo(snp_centerX)
  117. }
  118.  
  119.  
  120.  
  121. }
Add Comment
Please, Sign In to add comment