Skip to content

Commit

Permalink
Added possibility to set height/width/size of the view based on anoth…
Browse files Browse the repository at this point in the history
…er view's width/height/size

Updated changelog
  • Loading branch information
nakkht committed Aug 3, 2021
1 parent b199e9c commit dfe22ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to QuickConstraint project.

## v0.9.0 - [2021-08-04]

Added
* Missing documentation
* Possibility to set height/width/size of the view based on another view's width/height/size

## v0.8.1 - [2021-04-10]

Added
Expand Down
19 changes: 17 additions & 2 deletions Sources/QuickConstraint/View+AutoLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ public extension View {
return constraints
}

/// Creates constraints for width/height dimensions with specified size.
/// Creates constraints for width/height/size dimensions with specified size.
/// - Parameters:
/// - dimension: Dimension type to be used for determining which constraints to generate. Use `all` to generate width and height constraints simultaneously.
/// - dimension: Dimension type to be used for determining which constraints to generate. Use `size` to generate width and height constraints simultaneously.
/// - value: Size of set dimensions.
/// - Returns: Generated active constraints.
@inline(__always)
Expand All @@ -231,6 +231,21 @@ public extension View {
LayoutConstraint.activate(constraints)
return constraints
}

/// Creates constraints for width/height/size dimensions based on another view's width/height/size.
/// - Parameters:
/// - dimension: Dimension type to be used for determining which dimension constraints to generate. Use `size` to generate width and height constraints simultaneously..
/// - view: Parent of sibling view to use as a reference for constraints.
/// - Returns: Generated active constraints.
@discardableResult
func set(_ dimension: Dimension, to view: View) -> [LayoutConstraint] {
translatesAutoresizingMaskIntoConstraints = false
var constraints = [LayoutConstraint]()
if dimension.isWidth { constraints.append(widthAnchor.constraint(equalTo: view.widthAnchor)) }
if dimension.isHeight { constraints.append(heightAnchor.constraint(equalTo: view.heightAnchor)) }
LayoutConstraint.activate(constraints)
return constraints
}

/// Creates constraints based on center x and y axis.
/// - Parameters:
Expand Down

0 comments on commit dfe22ea

Please sign in to comment.