mvm_core_ui/MVMCoreUI/Molecules/Scroller.swift
Pfeil, Scott Robert f2db8528a7 threeLayer template
scroller molecule
border color.
remove default height
fix missing update view
2019-07-24 12:44:45 -04:00

43 lines
1.7 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: ViewConstrainingView {
public let scrollView = UIScrollView(frame: .zero)
public let contentView = MVMCoreUICommonViewsUtility.commonView()
override open func setupView() {
super.setupView()
guard scrollView.superview == nil else {
return
}
addConstrainedView(scrollView)
scrollView.addSubview(contentView)
if let constraints = (NSLayoutConstraint.pinView(toSuperview: contentView, useMargins: false) as NSDictionary).allValues as? [NSLayoutConstraint] {
NSLayoutConstraint.activate(constraints)
}
contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor, multiplier: 1.0, constant: -0.1).isActive = true
}
open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) {
guard let json = json, let moleculeJSON = json.optionalDictionaryForKey(KeyMolecule) else {
return
}
if molecule == nil {
if let moleculeView = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(forJSON: moleculeJSON, delegateObject: delegateObject, constrainIfNeeded: true) {
contentView.addSubview(moleculeView)
pinView(toSuperView: moleculeView)
molecule = moleculeView
}
} else {
molecule?.setWithJSON(moleculeJSON, delegateObject: delegateObject, additionalData: additionalData)
}
}
}