Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- class StandMapView: UIView {
- var titleLabel: UILabel = UILabel()
- var standMapImage: UIImageView = UIImageView()
- var hotspotImage: UIImageView = UIImageView()
- var hotspotTitleLabelArray: [UILabel] = []
- var hotspotTextArray: [UITextView] = []
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupView()
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- func bind(standMap: StandMap, hotspots: [Hotspot]) {
- titleLabel.text = standMap.title
- standMapImage.image = UIImage(named: standMap.mapImage)
- hotspotImage.image = UIImage(named:standMap.hotspotImage)
- for hotspot in hotspots {
- let hotspotTitle = UILabel()
- let hotspotText = UITextView()
- hotspotTitle.text = hotspot.title
- hotspotText.text = hotspot.text
- hotspotTitleLabelArray.append(hotspotTitle)
- hotspotTextArray.append(hotspotText)
- }
- }
- private func setupView() {
- let screenWidth = UIScreen.mainScreen().bounds.width
- let screenHeight = UIScreen.mainScreen().bounds.height
- self.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)
- titleLabel.translatesAutoresizingMaskIntoConstraints = false
- standMapImage.translatesAutoresizingMaskIntoConstraints = false
- hotspotImage.translatesAutoresizingMaskIntoConstraints = false
- self.backgroundColor = UIColor.blackColor()
- titleLabel.sizeToFit()
- titleLabel.frame = CGRect(x: screenWidth/2, y: 30, width: 0, height: 0)
- titleLabel.textAlignment = .Center
- titleLabel.numberOfLines = 0
- titleLabel.adjustsFontSizeToFitWidth = true
- titleLabel.textColor = UIColor.whiteColor()
- addSubview(titleLabel)
- }
- }
- import UIKit
- class StandMapViewController: UIViewController {
- var standMap: StandMap!
- var hotspots: [Hotspot] = []
- override func viewDidLoad() {
- super.viewDidLoad()
- Hotspot.all { hotspot in
- hotspot.forEach(self.assignHotspotVariable)
- }
- StandMap.build {standMap in
- standMap.forEach(self.assignStandMapVariable)
- }
- viewForStandMap(standMap, hotspots: hotspots)
- }
- private func assignStandMapVariable(standMap: StandMap) {
- self.standMap = standMap
- }
- private func assignHotspotVariable(hotspot: Hotspot) {
- hotspots.append(hotspot)
- }
- private func viewForStandMap(standMap: StandMap, hotspots: [Hotspot]) {
- let standMapView = StandMapView(frame: CGRectZero)
- standMapView.bind(standMap, hotspots: hotspots)
- view.addSubview(standMapView)
- }
- }
- titleLabel.frame.origin.x = 0.0 // put your value
- titleLabel.frame.origin.y = 0.0 // put your value
- self.view.layoutIfNeeded()
- private func setupView() {
- titleLabel.translatesAutoresizingMaskIntoConstraints = false
- standMapImage.translatesAutoresizingMaskIntoConstraints = false
- hotspotImage.translatesAutoresizingMaskIntoConstraints = false
- self.backgroundColor = UIColor.blackColor()
- titleLabel.textColor = UIColor.whiteColor()
- titleLabel.textAlignment = .Center
- titleLabel.numberOfLines = 0
- titleLabel.adjustsFontSizeToFitWidth = true
- addSubview(titleLabel)
- titleLabel.snp_makeConstraints { make in
- make.topMargin.equalTo(snp_topMargin).multipliedBy(60)
- make.centerX.equalTo(snp_centerX)
- }
- }
Add Comment
Please, Sign In to add comment