Skip to content

Commit 1cb436c

Browse files
committed
added that a constant can be passed to the equal height and width layout
1 parent 8485725 commit 1cb436c

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

Demo/Source/ViewController.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,24 @@ class ViewController: UIViewController {
7676
first.backgroundColor = UIColor(white: 0.0, alpha: 0.2)
7777
let second = UIView()
7878
second.backgroundColor = UIColor(white: 0.0, alpha: 0.4)
79+
let third = UIView()
80+
third.backgroundColor = .yellow
7981
self.view.addSubview(first)
8082
self.view.addSubview(second)
83+
self.view.addSubview(third)
8184

8285
first.layout.pin(.top, .leading, .trailing, insets: insets)
8386

8487
first.layout.stack(onTopOf: second, gap: 0)
8588
.equalHeight(with: second)
8689

8790
second.layout.pin(.leading, .trailing, .bottom, insets: insets)
91+
92+
third.layout
93+
.center()
94+
.equalHeight(with: first, constant: -100)
95+
.equalWidth(with: first, constant: -100)
96+
8897
} else {
8998
createView(color: UIColor(white: 0.0, alpha: 0.2), insets: insets)
9099
}

PinLayout/Main/Source/LayoutBuilder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ public class LayoutBuilder {
150150

151151

152152
@discardableResult
153-
public func equalWidth(with other: UIView, priority: UILayoutPriority = .required, multiplier: CGFloat = 1.0) -> LayoutBuilder {
154-
layout.setEqualConstant(view: view, andView: other, attribute: .width, priority: priority, multiplier: multiplier)
153+
public func equalWidth(with other: UIView, priority: UILayoutPriority = .required, multiplier: CGFloat = 1.0, constant: CGFloat = 0) -> LayoutBuilder {
154+
layout.setEqualConstant(view: view, andView: other, attribute: .width, priority: priority, multiplier: multiplier, constant: constant)
155155
return self
156156
}
157157

158158
@discardableResult
159-
public func equalHeight(with other: UIView, priority: UILayoutPriority = .required, multiplier: CGFloat = 1.0) -> LayoutBuilder {
160-
layout.setEqualConstant(view: view, andView: other, attribute: .height, priority: priority, multiplier: multiplier)
159+
public func equalHeight(with other: UIView, priority: UILayoutPriority = .required, multiplier: CGFloat = 1.0, constant: CGFloat = 0) -> LayoutBuilder {
160+
layout.setEqualConstant(view: view, andView: other, attribute: .height, priority: priority, multiplier: multiplier, constant: constant)
161161
return self
162162
}
163163

PinLayout/Test/Source/LayoutBuilder_Test.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,5 +795,32 @@ class LayoutBuilder_Test: PinLayout_Base_Test {
795795
assertThat(constraint.constant, equalTo(-11.0))
796796
}
797797

798+
func test_equalWidth_with_constant() throws {
799+
let secondView = UIView()
800+
toView.addSubview(view)
801+
toView.addSubview(secondView)
802+
803+
// when
804+
view.layout.equalWidth(with: secondView, constant: 100)
805+
806+
// then
807+
assertThat(toView.constraints, hasCount(1))
808+
let constraint = try XCTUnwrap(toView.constraints.first)
809+
assertThat(constraint.constant, equalTo(100))
810+
}
798811

812+
func test_equalHeigth_with_constant() throws {
813+
let secondView = UIView()
814+
toView.addSubview(view)
815+
toView.addSubview(secondView)
816+
817+
// when
818+
view.layout.equalHeight(with: secondView, constant: 99)
819+
820+
// then
821+
assertThat(toView.constraints, hasCount(1))
822+
let constraint = try XCTUnwrap(toView.constraints.first)
823+
assertThat(constraint.constant, equalTo(99))
824+
825+
}
799826
}

0 commit comments

Comments
 (0)