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
|
import Foundation
|
||||||
|
|
||||||
public extension NSLayoutConstraint {
|
public extension NSLayoutConstraint {
|
||||||
static func pinSubviewsCenter(leftView: UIView, rightView: UIView) {
|
|
||||||
guard let superView = leftView.superview else {
|
/// Pins the views vertically in the super view, allowing the super to expand depending on the tallest view. Shorter views are aligned center.
|
||||||
return
|
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
|
/// Pins the views vertically in the super view, allowing the super to expand depending on the tallest view. Shorter views are aligned top.
|
||||||
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: leftView.bottomAnchor).isActive = true
|
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)
|
let constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
||||||
constraint.priority = .defaultLow
|
constraint.priority = .defaultLow
|
||||||
constraint.isActive = true
|
constraint.isActive = true
|
||||||
|
}
|
||||||
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: leftView.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) {
|
||||||
rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: 16).isActive = true
|
guard let superView = leftView.superview else { return }
|
||||||
|
if alignTop {
|
||||||
rightView.centerYAnchor.constraint(equalTo: superView.centerYAnchor).isActive = true
|
pinViewsVerticalExpandableAlignTop([leftView, rightView])
|
||||||
superView.layoutMarginsGuide.rightAnchor.constraint(equalTo: rightView.rightAnchor).isActive = true
|
} else {
|
||||||
rightView.topAnchor.constraint(greaterThanOrEqualTo: superView.layoutMarginsGuide.topAnchor).isActive = true
|
pinViewsVerticalExpandableAlignCenter([leftView, rightView])
|
||||||
superView.layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: rightView.bottomAnchor).isActive = true
|
}
|
||||||
|
leftView.leadingAnchor.constraint(equalTo: superView.layoutMarginsGuide.leadingAnchor).isActive = true
|
||||||
constraint = rightView.topAnchor.constraint(equalTo: superView.layoutMarginsGuide.topAnchor)
|
superView.layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightView.trailingAnchor).isActive = true
|
||||||
constraint.priority = .defaultLow
|
rightView.leftAnchor.constraint(greaterThanOrEqualTo: leftView.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true
|
||||||
constraint.isActive = true
|
|
||||||
|
|
||||||
constraint = superView.layoutMarginsGuide.bottomAnchor.constraint(equalTo: rightView.bottomAnchor)
|
|
||||||
constraint.priority = .defaultLow
|
|
||||||
constraint.isActive = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,13 +10,14 @@ import UIKit
|
|||||||
|
|
||||||
@objcMembers open class ImageHeadlineBody: View {
|
@objcMembers open class ImageHeadlineBody: View {
|
||||||
let headlineBody = HeadlineBody(frame: .zero)
|
let headlineBody = HeadlineBody(frame: .zero)
|
||||||
let imageView = MFLoadImageView()
|
let imageView = MFLoadImageView(pinnedEdges: .all)
|
||||||
var constraintBetweenImageLabelsConstant: CGFloat = 16
|
var constraintBetweenImageLabelsConstant: CGFloat = 16
|
||||||
var constraintBetweenImageLabels: NSLayoutConstraint?
|
var constraintBetweenImageLabels: NSLayoutConstraint?
|
||||||
|
|
||||||
// MARK: - MFViewProtocol
|
// MARK: - MFViewProtocol
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
|
super.setupView()
|
||||||
guard subviews.count == 0 else {
|
guard subviews.count == 0 else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -26,23 +27,9 @@ import UIKit
|
|||||||
addSubview(headlineBody)
|
addSubview(headlineBody)
|
||||||
addSubview(imageView)
|
addSubview(imageView)
|
||||||
|
|
||||||
headlineBody.topAnchor.constraint(equalTo: topAnchor).isActive = true
|
NSLayoutConstraint.pinViewsVerticalExpandableAlignCenter([imageView, headlineBody])
|
||||||
rightAnchor.constraint(equalTo: headlineBody.rightAnchor).isActive = true
|
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.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 = headlineBody.leadingAnchor.constraint(equalTo: imageView.trailingAnchor, constant: constraintBetweenImageLabelsConstant)
|
||||||
constraintBetweenImageLabels?.isActive = true
|
constraintBetweenImageLabels?.isActive = true
|
||||||
|
|||||||
@ -27,7 +27,7 @@ import UIKit
|
|||||||
headlineBodyLink.headlineBody.styleListItem()
|
headlineBodyLink.headlineBody.styleListItem()
|
||||||
addSubview(headlineBodyLink)
|
addSubview(headlineBodyLink)
|
||||||
addSubview(toggle)
|
addSubview(toggle)
|
||||||
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBodyLink, rightView: toggle)
|
NSLayoutConstraint.pinViews(leftView: headlineBodyLink, rightView: toggle, alignTop: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - MVMCoreUIMoleculeViewProtoco
|
// MARK: - MVMCoreUIMoleculeViewProtoco
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import UIKit
|
|||||||
|
|
||||||
view.addSubview(headlineBody)
|
view.addSubview(headlineBody)
|
||||||
view.addSubview(toggle)
|
view.addSubview(toggle)
|
||||||
NSLayoutConstraint.pinSubviewsCenter(leftView: headlineBody, rightView: toggle)
|
NSLayoutConstraint.pinViews(leftView: headlineBody, rightView: toggle, alignTop: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK:- ModelMoleculeViewProtocol
|
// MARK:- ModelMoleculeViewProtocol
|
||||||
|
|||||||
@ -28,7 +28,7 @@ import UIKit
|
|||||||
addSubview(label)
|
addSubview(label)
|
||||||
addSubview(toggle)
|
addSubview(toggle)
|
||||||
label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
label.setContentHuggingPriority(UILayoutPriority.required, for: NSLayoutConstraint.Axis.vertical)
|
||||||
NSLayoutConstraint.pinSubviewsCenter(leftView: label, rightView: toggle)
|
NSLayoutConstraint.pinViews(leftView: label, rightView: toggle, alignTop: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK:- ModelMoleculeViewProtocol
|
// MARK:- ModelMoleculeViewProtocol
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user