Merge branch 'feature/improved_helpers' into 'develop'
Feature/improved helpers See merge request BPHV_MIPS/mvm_core_ui!255
This commit is contained in:
commit
3d2152f044
@ -9,36 +9,52 @@
|
||||
import Foundation
|
||||
|
||||
public extension NSLayoutConstraint {
|
||||
static func pinSubviewsCenter(leftView: UIView, rightView: UIView) {
|
||||
guard let superView = leftView.superview else {
|
||||
return
|
||||
|
||||
/// Pins the views vertically in the super view, allowing the super to expand depending on the tallest view. Shorter views are aligned center.
|
||||
static func pinViewsVerticalExpandableAlignCenter(_ views: [UIView]) {
|
||||
for view in views {
|
||||
guard let superView = view.superview else {
|
||||
return
|
||||
}
|
||||
view.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true
|
||||
view.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true
|
||||
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor).isActive = true
|
||||
|
||||
var constraint = view.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
|
||||
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
}
|
||||
leftView.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true
|
||||
leftView.leftAnchor.constraint(equalTo: superView.layoutMarginsGuide.leftAnchor).isActive = true
|
||||
leftView.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true
|
||||
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: leftView.bottomAnchor).isActive = true
|
||||
}
|
||||
|
||||
/// Pins the views vertically in the super view, allowing the super to expand depending on the tallest view. Shorter views are aligned top.
|
||||
static func pinViewsVerticalExpandableAlignTop(_ views: [UIView]) {
|
||||
for view in views {
|
||||
guard let superView = view.superview else {
|
||||
return
|
||||
}
|
||||
view.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor).isActive = true
|
||||
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor).isActive = true
|
||||
|
||||
var constraint = leftView.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
|
||||
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: leftView.bottomAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
|
||||
rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: 16).isActive = true
|
||||
|
||||
rightView.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true
|
||||
superView.layoutMarginsGuide.rightAnchor.constraint(equalTo: rightView.rightAnchor).isActive = true
|
||||
rightView.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true
|
||||
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: rightView.bottomAnchor).isActive = true
|
||||
|
||||
constraint = rightView.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
|
||||
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: rightView.bottomAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
let constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
/// Pins a view to the left and a view to the right, flexible space in between. The super can expand depending on the taller view. Shorter views are aligned top if alignTop true, else aligned center.
|
||||
static func pinViews(leftView: UIView, rightView: UIView, alignTop: Bool) {
|
||||
guard let superView = leftView.superview else { return }
|
||||
if alignTop {
|
||||
pinViewsVerticalExpandableAlignTop([leftView, rightView])
|
||||
} else {
|
||||
pinViewsVerticalExpandableAlignCenter([leftView, rightView])
|
||||
}
|
||||
leftView.leadingAnchor.constraint(equalTo: superView.layoutMarginsGuide.leadingAnchor).isActive = true
|
||||
superView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightView.trailingAnchor).isActive = true
|
||||
rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,13 +10,14 @@ import UIKit
|
||||
|
||||
@objcMembers open class ImageHeadlineBody: View {
|
||||
let headlineBody = HeadlineBody(frame: .zero)
|
||||
let imageView = MFLoadImageView()
|
||||
let imageView = MFLoadImageView(pinnedEdges: .all)
|
||||
var constraintBetweenImageLabelsConstant: CGFloat = 16
|
||||
var constraintBetweenImageLabels: NSLayoutConstraint?
|
||||
|
||||
// MARK: - MFViewProtocol
|
||||
|
||||
open override func setupView() {
|
||||
super.setupView()
|
||||
guard subviews.count == 0 else {
|
||||
return
|
||||
}
|
||||
@ -26,23 +27,9 @@ import UIKit
|
||||
addSubview(headlineBody)
|
||||
addSubview(imageView)
|
||||
|
||||
headlineBody.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
||||
NSLayoutConstraint.pinViewsVerticalExpandableAlignCenter([imageView, headlineBody])
|
||||
rightAnchor.constraint(equalTo: headlineBody.rightAnchor).isActive = true
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: headlineBody.bottomAnchor).isActive = true
|
||||
var constraint = bottomAnchor.constraint(equalTo: headlineBody.bottomAnchor)
|
||||
constraint.priority = .defaultLow
|
||||
constraint.isActive = true
|
||||
|
||||
imageView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
||||
imageView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
|
||||
imageView.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
|
||||
bottomAnchor.constraint(greaterThanOrEqualTo: imageView.bottomAnchor).isActive = true
|
||||
constraint = bottomAnchor.constraint(equalTo: imageView.bottomAnchor)
|
||||
constraint.priority = UILayoutPriority(rawValue: 200)
|
||||
constraint.isActive = true
|
||||
constraint = imageView.topAnchor.constraint(equalTo: topAnchor)
|
||||
constraint.priority = UILayoutPriority(rawValue: 200)
|
||||
constraint.isActive = true
|
||||
|
||||
constraintBetweenImageLabels = headlineBody.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: constraintBetweenImageLabelsConstant)
|
||||
constraintBetweenImageLabels?.isActive = true
|
||||
|
||||
@ -27,7 +27,7 @@ import UIKit
|
||||
headlineBodyLink.headlineBody.styleListItem()
|
||||
addSubview(headlineBodyLink)
|
||||
addSubview(toggle)
|
||||
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBodyLink, rightView: toggle)
|
||||
NSLayoutConstraint.pinViews(leftView: headlineBodyLink, rightView: toggle, alignTop: false)
|
||||
}
|
||||
|
||||
// MARK: - MVMCoreUIMoleculeViewProtoco
|
||||
|
||||
@ -31,7 +31,7 @@ import UIKit
|
||||
|
||||
view.addSubview(headlineBody)
|
||||
view.addSubview(toggle)
|
||||
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: toggle)
|
||||
NSLayoutConstraint.pinViews(leftView: headlineBody, rightView: toggle, alignTop: false)
|
||||
}
|
||||
|
||||
// MARK:- ModelMoleculeViewProtocol
|
||||
|
||||
@ -28,7 +28,7 @@ import UIKit
|
||||
addSubview(label)
|
||||
addSubview(toggle)
|
||||
label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
||||
NSLayoutConstraint.pinSubviewsCenter(leftView: label, rightView: toggle)
|
||||
NSLayoutConstraint.pinViews(leftView: label, rightView: toggle, alignTop: false)
|
||||
}
|
||||
|
||||
// MARK:- ModelMoleculeViewProtocol
|
||||
|
||||
Loading…
Reference in New Issue
Block a user