Skip to content

Commit dfe22ea

Browse files
committed
Added possibility to set height/width/size of the view based on another view's width/height/size
Updated changelog
1 parent b199e9c commit dfe22ea

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to QuickConstraint project.
44

5+
## v0.9.0 - [2021-08-04]
6+
7+
Added
8+
* Missing documentation
9+
* Possibility to set height/width/size of the view based on another view's width/height/size
10+
511
## v0.8.1 - [2021-04-10]
612

713
Added

Sources/QuickConstraint/View+AutoLayout.swift

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,9 @@ public extension View {
216216
return constraints
217217
}
218218

219-
/// Creates constraints for width/height dimensions with specified size.
219+
/// Creates constraints for width/height/size dimensions with specified size.
220220
/// - Parameters:
221-
/// - dimension: Dimension type to be used for determining which constraints to generate. Use `all` to generate width and height constraints simultaneously.
221+
/// - dimension: Dimension type to be used for determining which constraints to generate. Use `size` to generate width and height constraints simultaneously.
222222
/// - value: Size of set dimensions.
223223
/// - Returns: Generated active constraints.
224224
@inline(__always)
@@ -231,6 +231,21 @@ public extension View {
231231
LayoutConstraint.activate(constraints)
232232
return constraints
233233
}
234+
235+
/// Creates constraints for width/height/size dimensions based on another view's width/height/size.
236+
/// - Parameters:
237+
/// - dimension: Dimension type to be used for determining which dimension constraints to generate. Use `size` to generate width and height constraints simultaneously..
238+
/// - view: Parent of sibling view to use as a reference for constraints.
239+
/// - Returns: Generated active constraints.
240+
@discardableResult
241+
func set(_ dimension: Dimension, to view: View) -> [LayoutConstraint] {
242+
translatesAutoresizingMaskIntoConstraints = false
243+
var constraints = [LayoutConstraint]()
244+
if dimension.isWidth { constraints.append(widthAnchor.constraint(equalTo: view.widthAnchor)) }
245+
if dimension.isHeight { constraints.append(heightAnchor.constraint(equalTo: view.heightAnchor)) }
246+
LayoutConstraint.activate(constraints)
247+
return constraints
248+
}
234249

235250
/// Creates constraints based on center x and y axis.
236251
/// - Parameters:

0 commit comments

Comments
 (0)