Created
December 26, 2018 09:04
-
-
Save nathantannar4/d7e7c457da6788a662307f495b7ad242 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class RowView<LeftViewType: UIView, RightViewType: UIView, AccessoryViewType: UIView>: View { | |
let leftView = LeftViewType() | |
let rightView = RightViewType() | |
let accessoryView = AccessoryViewType() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
addSubviews(leftView, rightView, accessoryView) | |
let xInset = Stylesheet.Layout.Padding.edgeLeadingTrailing | |
let yInset = Stylesheet.Layout.Padding.edgeTopBottom | |
let spacing = Stylesheet.Layout.Padding.subviewSpacing | |
leftView.anchorIfNeeded(topAnchor, bottom: bottomAnchor, topConstant: yInset, bottomConstant: yInset) | |
leftView.anchorCenterYToSuperview() | |
leftView.anchor(left: leftAnchor, right: rightView.leftAnchor, leftConstant: xInset, rightConstant: spacing) | |
leftView.setContentCompressionResistancePriority( | |
.defaultHigh, | |
for: .horizontal | |
) | |
leftView.setContentHuggingPriority( | |
.defaultHigh, | |
for: .horizontal | |
) | |
rightView.anchorIfNeeded(topAnchor, bottom: bottomAnchor, right: rightAnchor, topConstant: yInset, bottomConstant: yInset) | |
rightView.anchor(left: leftView.rightAnchor, leftConstant: spacing) | |
rightView.anchorCenterYToSuperview() | |
accessoryView.anchorIfNeeded(topAnchor, bottom: bottomAnchor, topConstant: yInset, bottomConstant: yInset, widthConstant: 0) | |
accessoryView.anchorCenterYToSuperview() | |
accessoryView.anchor(left: rightView.rightAnchor, right: rightAnchor, leftConstant: spacing, rightConstant: xInset) | |
accessoryView.setContentCompressionResistancePriority( | |
.defaultHigh, | |
for: .horizontal | |
) | |
accessoryView.setContentHuggingPriority( | |
.defaultHigh, | |
for: .horizontal | |
) | |
heightAnchor.constraint(greaterThanOrEqualToConstant: 60).isActive = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment