mvm_core_ui/MVMCoreUI/Molecules/Scroller.swift
2020-02-27 13:45:15 -05:00

47 lines
1.9 KiB
Swift

//
// Scroller.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 7/23/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
@objcMembers open class Scroller: Container {
public let scrollView = UIScrollView(frame: .zero)
public let contentView = MVMCoreUICommonViewsUtility.commonView()
override open func setupView() {
super.setupView()
guard scrollView.superview == nil else {
return
}
translatesAutoresizingMaskIntoConstraints = false
scrollView.translatesAutoresizingMaskIntoConstraints = false
addSubview(scrollView)
NSLayoutConstraint.constraintPinSubview(toSuperview: scrollView)
contentView.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(contentView)
NSLayoutConstraint.constraintPinSubview(toSuperview: contentView)
let constraint = contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, multiplier: 1.0)
constraint.priority = UILayoutPriority(rawValue: 999)
constraint.isActive = true
}
public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
if let casteModel = model as? ScrollerModel {
if view != nil {
(view as? ModelMoleculeViewProtocol)?.set(with: casteModel.molecule, delegateObject, additionalData)
} else {
if let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(casteModel.molecule, delegateObject) {
contentView.addSubview(molecule)
molecule.translatesAutoresizingMaskIntoConstraints = false
containerHelper.constrainView(molecule)
}
}
}
super.set(with: model, delegateObject, additionalData)
}
}