Added Center X & Y constraints and modified code based on constraints
This commit is contained in:
parent
2d7bdf9a8f
commit
86e91c3ac7
@ -92,34 +92,38 @@ open class Pagination: View {
|
|||||||
open override func initialSetup() {
|
open override func initialSetup() {
|
||||||
super.initialSetup()
|
super.initialSetup()
|
||||||
|
|
||||||
addSubview(containerView)
|
collectionContainerView.addSubview(collectionView)
|
||||||
containerView
|
|
||||||
.pinTop()
|
|
||||||
.pinBottom()
|
|
||||||
containerView.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor).activate()
|
|
||||||
trailingAnchor.constraint(greaterThanOrEqualTo: containerView.trailingAnchor).activate()
|
|
||||||
containerView.centerXAnchor.constraint(equalTo: centerXAnchor).activate()
|
|
||||||
containerView.widthAnchor.constraint(equalToConstant: maxWidth).activate()
|
|
||||||
containerView.heightAnchor.constraint(equalToConstant: 44).activate()
|
|
||||||
containerView.addSubview(previousButton)
|
containerView.addSubview(previousButton)
|
||||||
containerView.addSubview(collectionContainerView)
|
containerView.addSubview(collectionContainerView)
|
||||||
containerView.addSubview(nextButton)
|
containerView.addSubview(nextButton)
|
||||||
collectionContainerView.addSubview(collectionView)
|
addSubview(containerView)
|
||||||
|
|
||||||
|
containerView
|
||||||
|
.pinTop()
|
||||||
|
.pinBottom()
|
||||||
|
.pinLeadingGreaterThanOrEqualTo()
|
||||||
|
.pinTrailingLessThanOrEqualTo()
|
||||||
|
.pinCenterX()
|
||||||
|
.width(maxWidth)
|
||||||
|
.height(44)
|
||||||
|
|
||||||
previousButton
|
previousButton
|
||||||
.pinTop()
|
.pinTop()
|
||||||
.pinBottom()
|
.pinBottom()
|
||||||
.pinLeading()
|
.pinLeading()
|
||||||
|
.pinTrailingGreaterThanOrEqualTo(collectionContainerView.leadingAnchor)
|
||||||
|
|
||||||
previousButton.trailingAnchor.constraint(greaterThanOrEqualTo: collectionContainerView.leadingAnchor).activate()
|
|
||||||
collectionContainerView.trailingAnchor.constraint(greaterThanOrEqualTo: nextButton.leadingAnchor).activate()
|
|
||||||
collectionContainerView
|
collectionContainerView
|
||||||
|
.pinTrailingGreaterThanOrEqualTo(nextButton.leadingAnchor)
|
||||||
.pinTop()
|
.pinTop()
|
||||||
.pinBottom()
|
.pinBottom()
|
||||||
collectionView.heightAnchor.constraint(equalToConstant: VDSLayout.Spacing.space4X.value).activate()
|
|
||||||
collectionView.centerYAnchor.constraint(equalTo: centerYAnchor).activate()
|
collectionView
|
||||||
collectionView.centerXAnchor.constraint(equalTo: collectionContainerView.centerXAnchor).activate()
|
.height(VDSLayout.Spacing.space4X.value)
|
||||||
collectionViewWidthAnchor = collectionView.widthAnchor.constraint(equalToConstant: 92)
|
.pinCenterY()
|
||||||
collectionViewWidthAnchor?.activate()
|
.pinCenterX()
|
||||||
|
|
||||||
|
collectionViewWidthAnchor = collectionView.width(constant: 92)
|
||||||
|
|
||||||
nextButton
|
nextButton
|
||||||
.pinTop()
|
.pinTop()
|
||||||
|
|||||||
@ -48,7 +48,7 @@ final class PaginationCellItem: UICollectionViewCell {
|
|||||||
contentView.addSubview(containerView)
|
contentView.addSubview(containerView)
|
||||||
containerView.pinToSuperView()
|
containerView.pinToSuperView()
|
||||||
indexLabel.pinToSuperView()
|
indexLabel.pinToSuperView()
|
||||||
indexLabel.widthAnchor.constraint(greaterThanOrEqualToConstant: VDSLayout.Spacing.space5X.value).activate()
|
indexLabel.widthGreaterThanEqualTo(VDSLayout.Spacing.space5X.value)
|
||||||
contentView.backgroundColor = .clear
|
contentView.backgroundColor = .clear
|
||||||
containerView.backgroundColor = .clear
|
containerView.backgroundColor = .clear
|
||||||
indexLabel.backgroundColor = .clear
|
indexLabel.backgroundColor = .clear
|
||||||
|
|||||||
@ -478,7 +478,159 @@ extension LayoutConstraintable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Center X Constraints
|
||||||
|
//--------------------------------------------------
|
||||||
|
extension LayoutConstraintable {
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor.
|
||||||
|
/// - Parameter constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterX(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
|
||||||
|
pinCenterX(nil, constant)
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor to a specific XAxisAnchor.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerXAnchor.
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterX(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
|
||||||
|
pinCenterX(anchor: anchor, constant: constant)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor to a specific XAxisAnchor passed in using a lessThanOrEqualTo Constraint
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerXAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterXLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
|
||||||
|
pinCenterXLessThanOrEqualTo(anchor: anchor, constant: constant)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerXAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterXGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self {
|
||||||
|
pinCenterXGreaterThanOrEqualTo(anchor: anchor, constant: constant)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor for the constant passed into the method.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerXAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: The Constraint that was created.
|
||||||
|
public func pinCenterX(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
|
||||||
|
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.centerXAnchor
|
||||||
|
guard let found else { return nil }
|
||||||
|
return centerXAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerXAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: The Constraint that was created.
|
||||||
|
public func pinCenterXLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
|
||||||
|
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.centerXAnchor
|
||||||
|
guard let found else { return nil }
|
||||||
|
return centerXAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerXAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerXAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: The Constraint that was created.
|
||||||
|
public func pinCenterXGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
|
||||||
|
let found: NSLayoutXAxisAnchor? = anchor ?? superview?.centerXAnchor
|
||||||
|
guard let found else { return nil }
|
||||||
|
return centerXAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Center Y Constraints
|
||||||
|
//--------------------------------------------------
|
||||||
|
extension LayoutConstraintable {
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor.
|
||||||
|
/// - Parameter constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterY(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
|
||||||
|
pinCenterY(nil, constant)
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor to a specific YAxisAnchor.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerYAnchor.
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterY(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
|
||||||
|
pinCenterY(anchor: anchor, constant: constant)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerYAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterYLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self {
|
||||||
|
pinCenterYLessThanOrEqualTo(anchor: anchor, constant: constant)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerYAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: Yourself.
|
||||||
|
public func pinCenterYGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self {
|
||||||
|
pinCenterXGreaterThanOrEqualTo(anchor: anchor, constant: constant)
|
||||||
|
return self
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor for the constant passed into the method.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerYAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: The Constraint that was created.
|
||||||
|
public func pinCenterY(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
|
||||||
|
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.centerYAnchor
|
||||||
|
guard let found else { return nil }
|
||||||
|
return centerYAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor with the constant passed in using a lessThanOrEqualTo Constraint.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerYAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: The Constraint that was created.
|
||||||
|
public func pinCenterYLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
|
||||||
|
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.centerYAnchor
|
||||||
|
guard let found else { return nil }
|
||||||
|
return centerYAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
|
||||||
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
/// Adds a centerYAnchor with the constant passed in using a greaterThanOrEqualTo Constraint.
|
||||||
|
/// - Parameter anchor:The anchor in which to attach the centerYAnchor
|
||||||
|
/// - constant: Constant size.
|
||||||
|
/// - Returns: The Constraint that was created.
|
||||||
|
public func pinCenterYGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? {
|
||||||
|
let found: NSLayoutYAxisAnchor? = anchor ?? superview?.centerYAnchor
|
||||||
|
guard let found else { return nil }
|
||||||
|
return centerYAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true }
|
||||||
|
}
|
||||||
|
}
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Implementations
|
// MARK: - Implementations
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user