// // ImageHeadlineBody.swift // MVMCoreUI // // Created by Scott Pfeil on 8/1/19. // Copyright © 2019 Verizon Wireless. All rights reserved. // import UIKit @objcMembers open class ImageHeadlineBody: ViewConstrainingView { let headlineBody = HeadlineBody(frame: .zero) let imageView = MFLoadImageView() var constraintBetweenImageLabelsConstant: CGFloat = 16 var constraintBetweenImageLabels: NSLayoutConstraint? // MARK: - MFViewProtocol open override func setupView() { guard subviews.count == 0 else { return } MVMCoreUIUtility.setMarginsFor(self, leading: 0, top: 0, trailing: 0, bottom: 0) headlineBody.headlineLabel.styleB1(true) headlineBody.spaceBetweenLabelsConstant = 0 addSubview(headlineBody) addSubview(imageView) NSLayoutConstraint.pinViewTop(toSuperview: headlineBody, useMargins: true, constant: 0).isActive = true NSLayoutConstraint.pinViewRight(toSuperview: headlineBody, useMargins: true, constant: 0).isActive = true layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: headlineBody.bottomAnchor).isActive = true var constraint = NSLayoutConstraint.pinViewBottom(toSuperview: headlineBody, useMargins: true, constant: 0) constraint.priority = .defaultLow constraint.isActive = true imageView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true NSLayoutConstraint.pinViewLeft(toSuperview: imageView, useMargins: true, constant: 0).isActive = true imageView.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor).isActive = true layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: imageView.bottomAnchor).isActive = true constraint = NSLayoutConstraint.pinViewBottom(toSuperview: imageView, useMargins: true, constant: 0) constraint.priority = UILayoutPriority(rawValue: 200) constraint.isActive = true constraint = NSLayoutConstraint.pinViewTop(toSuperview: imageView, useMargins: true, constant: 0) constraint.priority = UILayoutPriority(rawValue: 200) constraint.isActive = true constraintBetweenImageLabels = headlineBody.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: constraintBetweenImageLabelsConstant) constraintBetweenImageLabels?.isActive = true } open override func updateView(_ size: CGFloat) { super.updateView(size) headlineBody.updateView(size) imageView.updateView(size) } // MARK: - MVMCoreUIMoleculeViewProtocol open override func setWithJSON(_ json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable : Any]?) { super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData) headlineBody.setWithJSON(json?.optionalDictionaryForKey("headlineBody"), delegateObject: delegateObject, additionalData: additionalData) let imageJSON = json?.optionalDictionaryForKey("image") imageView.setWithJSON(imageJSON, delegateObject: delegateObject, additionalData: additionalData) constraintBetweenImageLabels?.constant = imageJSON != nil ? constraintBetweenImageLabelsConstant : 0 } open override func setAsMolecule() { super.setAsMolecule() headlineBody.setAsMolecule() imageView.setAsMolecule() } open override func reset() { super.reset() headlineBody.reset() headlineBody.headlineLabel.styleB1(true) headlineBody.spaceBetweenLabelsConstant = 0 imageView.reset() } public override static func estimatedHeight(forRow json: [AnyHashable : Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { return 95 } }