Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public typealias Stack = UIStackView
- public extension Stack {
- @nonobjc public convenience init(_ views: UIView..., with: (UIStackView) -> Void = { _ in }) {
- self.init(arrangedSubviews: views)
- with(self)
- }
- @nonobjc public convenience init(_ views: [UIView], axis: UILayoutConstraintAxis = .horizontal, spacing: CGFloat = 0, alignment: UIStackViewAlignment = .fill, distribution: UIStackViewDistribution = .fill) {
- self.init(arrangedSubviews: views)
- self.axis = axis
- self.spacing = spacing
- self.alignment = alignment
- self.distribution = distribution
- }
- @nonobjc public convenience init(style: ((UIStackView) -> Void)..., views: [UIView]) {
- self.init(arrangedSubviews: views)
- style.forEach { $0(self) }
- }
- }
- public final class Spacer: UIView { // using `UIView` and not `UILayoutGuide` to support stack views
- @nonobjc public convenience init(width: CGFloat) { self.init(.width(width)) }
- @nonobjc public convenience init(minWidth: CGFloat) { self.init(.width(minWidth), isFlexible: true) }
- @nonobjc public convenience init(height: CGFloat) { self.init(.height(height)) }
- @nonobjc public convenience init(minHeight: CGFloat) { self.init(.height(minHeight), isFlexible: true) }
- private enum Dimension {
- case width(CGFloat), height(CGFloat)
- }
- private init(_ dimension: Dimension, isFlexible: Bool = false) {
- super.init(frame: .zero)
- Constraints(for: self) {
- switch dimension {
- case let .width(width):
- $0.width.set(width, relation: isFlexible ? .greaterThanOrEqual : .equal)
- if isFlexible { $0.width.set(width).priority = UILayoutPriority(42) } // disambiguate
- $0.height.set(0).priority = UILayoutPriority(42) // disambiguate
- case let .height(height):
- $0.height.set(height, relation: isFlexible ? .greaterThanOrEqual : .equal)
- if isFlexible { $0.height.set(height).priority = UILayoutPriority(42) } // disambiguate
- $0.width.set(0).priority = UILayoutPriority(42) // disambiguate
- }
- }
- }
- public required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
- }
- // don't draw anything
- override public class var layerClass: AnyClass { return CATransformLayer.self }
- override public var backgroundColor: UIColor? { get { return nil } set { return } }
- }
- // MARK: Insets
- public typealias Insets = UIEdgeInsets
- public extension UIEdgeInsets {
- public init(_ all: CGFloat) { self = UIEdgeInsetsMake(all, all, all, all) }
- }
Add Comment
Please, Sign In to add comment