Skip to content

Commit 53faea5

Browse files
author
Luc Dion
authored
Merge pull request #81 from mirego/update_hCenter_vCenter_float_percent
Breaking change related to hCenter(CGFloat), hCenter(percent), vCenter(CGFloat), vCenter(percent)
2 parents ec384ed + 3c9c7d2 commit 53faea5

File tree

10 files changed

+106
-67
lines changed

10 files changed

+106
-67
lines changed

CHANGELOG.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,27 @@
66

77

88
# Change Log
9+
## [1.3.0](https://github.com/mirego/PinLayout/releases/tag/1.3.0)
10+
Released on 2017-08-18.
11+
12+
#### Change
13+
* **Breaking change related to hCenter(CGFloat), hCenter(percent), vCenter(CGFloat), vCenter(percent)**:
14+
* **`vCenter(_ value: CGFloat)`** and **`vCenter(_ percent: Percent)`**:
15+
The value specifies the distance vertically of the view's center **related to the superview's center** in pixels. Previously it was related to the **superview's top edge**.
16+
* **`hCenter(_ value: CGFloat)`** and **`hCenter(_ percent: Percent)`**:
17+
The value specifies the distance horizontally of the view's center **related to the superview's center** in pixels. Previously it was related to the **superview's left edge**.
918

1019
## [1.2.4](https://github.com/mirego/PinLayout/releases/tag/1.2.4)
1120
#### Change
1221
* Add methods to pin hCenter and vCenter to any other view's edges (including the new hCenter and vCenter edges)
13-
* New methods:
14-
* func hCenter(to edge: HorizontalEdge) -> PinLayout
15-
* func vCenter(to edge: VerticalEdge) -> PinLayout
16-
* New UIView's edges:
17-
* UIView.edge.hCenter
18-
* UIView.edge.vCenter
22+
* **New methods**:
23+
* **`hCenter(to: edge)`**
24+
Position horizontally the view's center directly on another view’s edge (left/hCenter/right)
25+
* **`vCenter(to: edge)`**
26+
Position vertically the view's center directly on another view’s edge (top/vCenter/bottom).
27+
* **New UIView's edges**:
28+
* **`UIView.edge.hCenter`**
29+
* **`UIView.edge.vCenter`**
1930
* Added by [Luc Dion](https://github.com/lucdion) in Pull Request [#80](https://github.com/mirego/PinLayout/pull/80)
2031

2132
## [1.2.3](https://github.com/mirego/PinLayout/releases/tag/1.2.3)

Example/PinLayoutSample/UI/Examples/TableViewExample/TableViewExampleViewController.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ class TableViewExampleViewController: BaseViewController {
5252
mainView.configure(methods: [
5353
Method(name: "top(_ value: CGFloat)", description: "The value specifies the top edge distance from the superview's top edge in pixels."),
5454
Method(name: "top(_ percent: Percent)", description: "The value specifies the top edge distance from the superview's top edge in percentage of its superview's height."),
55-
Method(name: "left(_ value: CGFloat)", description: "The value specifies the left edge distance from the superview's left edge in pixels. The value specifies the left edge distance from the superview's left edge in pixels."),
56-
Method(name: "left(_ percent: Percent)", description: "The value specifies the left edge distance from the superview's left edge in percentage of its superview's width."),
55+
Method(name: "vCenter(_ value: CGFloat)", description: "The value specifies the distance vertically of the view's center related to the superview's center in pixels."),
56+
Method(name: "vCenter(_ percent: Percent)", description: "The value specifies the distance vertically of the view's center related to the superview's center in percentage of its superview's height."),
5757
Method(name: "bottom(_ value: CGFloat)", description: "The value specifies the bottom edge distance from the superview's bottom edge in pixels."),
5858
Method(name: "bottom(_ percent: Percent)", description: "The value specifies the bottom edge distance from the superview's bottom edge in percentage of its superview's height."),
59+
60+
Method(name: "left(_ value: CGFloat)", description: "The value specifies the left edge distance from the superview's left edge in pixels. The value specifies the left edge distance from the superview's left edge in pixels."),
61+
Method(name: "left(_ percent: Percent)", description: "The value specifies the left edge distance from the superview's left edge in percentage of its superview's width."),
62+
Method(name: "hCenter(_ value: CGFloat)", description: "The value specifies the distance horizontally of the view's center related to the superview's center in pixels."),
63+
Method(name: "hCenter(_ percent: Percent)", description: "The value specifies the distance horizontally of the view's center related to the superview's center in percentage of its superview's height."),
5964
Method(name: "right(_ value: CGFloat)", description: "The value specifies the right edge distance from the superview's right edge in pixels."),
60-
Method(name: "right(_ percent: Percent)", description: "The value specifies the right edge distance from the superview's right edge in percentage of its superview's width."),
61-
Method(name: "hCenter(_ value: CGFloat)", description: "The value specifies the horizontal center distance from the superview's left edge in pixels."),
62-
Method(name: "hCenter(_ percent: Percent)", description: "The value specifies the horizontal center distance from the superview's left edge in percentage of its superview's width."),
63-
Method(name: "vCenter(_ value: CGFloat)", description: "The value specifies the vertical center distance from the superview's top edge in pixels."),
64-
Method(name: "vCenter(_ percent: Percent)", description: "The value specifies the vertical center distance from the superview's top edge in percentage of its superview's height.")
65+
Method(name: "right(_ percent: Percent)", description: "The value specifies the right edge distance from the superview's right edge in percentage of its superview's width.")
6566
])
6667
}
6768
}

PinLayout.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Pod::Spec.new do |s|
1616
#
1717

1818
s.name = "PinLayout"
19-
s.version = "1.2.4"
19+
s.version = "1.3.0"
2020
s.summary = "Fast Swift UIViews layouting without auto layout. No magic, pure code, full control and blazing fast. Concise syntax, intuitive, readable & chainable."
2121

2222
# This description is used to generate tags and improve search results.

README.md

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ These results also mean that **PinLayout is by far faster than any layout framew
176176

177177
[See here a more complete details, results and explanation of the benchmark](docs/Benchmark.md).
178178

179-
<p align="center"> Tested on a iPhone 6S iOS 10.3.2</p>
180179
<p align="center">
181-
<img src="docs/Benchmark/benchmark_iphone6s.png" alt="PinLayout Performance" width=600/>
180+
<img src="docs/Benchmark/benchmark_iphone7.png" alt="PinLayout Performance" width=600/>
182181
</p>
183182

184183
<br/>
@@ -221,9 +220,9 @@ The value specifies the top edge distance from the superview's top edge in pixel
221220
* **`top(_ percent: Percent)`**
222221
The value specifies the top edge distance from the superview's top edge in percentage of its superview's height.
223222
* **`vCenter(_ value: CGFloat)`**
224-
The value specifies the vertical center distance from the superview's top edge in pixels.
223+
The value specifies the distance vertically of the view's center related to the superview's center in pixels. A positive value move the view down and a negative value move it up relative to the superview's center.
225224
* **`vCenter(_ percent: Percent)`**
226-
The value specifies the vertical center distance from the superview's top edge in percentage of its superview's height.
225+
The value specifies the distance vertically of the view's center related to the superview's center in percentage of its superview's height. A positive value move the view down and a negative value move it up relative to the superview's center.
227226
* **`bottom(_ value: CGFloat)`**
228227
The value specifies the bottom edge **distance from the superview's bottom edge** in pixels.
229228
* **`bottom(_ percent: Percent)`**
@@ -233,9 +232,9 @@ The value specifies the left edge distance from the superview's left edge in pix
233232
* **`left(_ percent: Percent)`**
234233
The value specifies the left edge distance from the superview's left edge in percentage of its superview's width.
235234
* **`hCenter(_ value: CGFloat)`**
236-
The value specifies the horizontal center distance from the superview's left edge in pixels.
235+
The value specifies the distance horizontally of the view's center related to the superview's center in pixels. A positive value move the view to the right and a negative value move it to the left relative to the superview's center.
237236
* **`hCenter(_ percent: Percent)`**
238-
The value specifies the horizontal center distance from the superview's left edge in percentage of its superview's width.
237+
The value specifies the distance horizontally of the view's center related to the superview's center in percentage of its superview's width. A positive value move the view to the right and a negative value move it to the left relative to the superview's center.
239238
* **`right(_ value: CGFloat)`**
240239
The value specifies the right edge **distance from the superview's right edge** in pixels.
241240
* **`right(_ percent: Percent)`**
@@ -256,9 +255,9 @@ In RTL direction the value specifies the left edge distance from the superview's
256255
###### Usage Examples:
257256

258257
```swift
259-
view.pin.top(20).left(20)
260-
view.pin.top(25%).hCenter(0)
261-
view.pin.left(12).vCenter(100)
258+
view.pin.top(20).bottom(20) // The view has a top margin and a bottom margin of 20 pixels
259+
view.pin.top(25%).hCenter(0) // The view is centered horizontally
260+
view.pin.left(12).vCenter(0) // The view is centered vertically
262261
view.pin.start(20).end(20)
263262
```
264263

@@ -373,17 +372,23 @@ In RTL direction it position the view's bottom edge directly on another view’s
373372
view.pin.left(to: view1.edge.right).top(to: view2.edge.right)
374373
```
375374

376-
###### Example:
377-
Layout using an edge.
378-
379-
The following example will layout the view B left edge on the view A right edge. It only changes the view B left coordinate.
375+
###### Example 1:
376+
This example layout the view B left edge on the view A right edge. It only changes the view B left coordinate.
380377

381378
![](docs/example-edges.png)
382379

383380
```swift
384381
viewB.pin.left(to: viewA.edge.right)
385382
```
386383

384+
###### Example 2:
385+
This example center horizontally the view B inside the view A with a top margin of 10 from the same view.
386+
![](docs/pinlayout_example_hCenter_edge.png)
387+
388+
```swift
389+
aView.pin.top(to: bView.edge.top).hCenter(to: bView.edge.hCenter).marginTop(10)
390+
```
391+
387392
<br/>
388393

389394
## Anchors <a name="anchors"></a>

Sources/PinLayoutImpl.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,16 @@ class PinLayoutImpl: PinLayout {
192192
@discardableResult
193193
func hCenter(_ value: CGFloat) -> PinLayout {
194194
func context() -> String { return "hCenter(\(value))" }
195-
setHorizontalCenter(value, context)
195+
guard let layoutSuperview = layoutSuperview(context) else { return self }
196+
setHorizontalCenter((layoutSuperview.frame.width / 2) + value, context)
196197
return self
197198
}
198199

199200
@discardableResult
200201
func hCenter(_ percent: Percent) -> PinLayout {
201202
func context() -> String { return "hCenter(\(percent))" }
202203
guard let layoutSuperview = layoutSuperview(context) else { return self }
203-
setHorizontalCenter(percent.of(layoutSuperview.frame.width), context)
204+
setHorizontalCenter((layoutSuperview.frame.width / 2) + percent.of(layoutSuperview.frame.width), context)
204205
return self
205206
}
206207

@@ -215,15 +216,16 @@ class PinLayoutImpl: PinLayout {
215216
@discardableResult
216217
func vCenter(_ value: CGFloat) -> PinLayout {
217218
func context() -> String { return "vCenter(\(value))" }
218-
setVerticalCenter(value, context)
219+
guard let layoutSuperview = layoutSuperview(context) else { return self }
220+
setVerticalCenter((layoutSuperview.frame.height / 2) + value, context)
219221
return self
220222
}
221223

222224
@discardableResult
223225
func vCenter(_ percent: Percent) -> PinLayout {
224226
func context() -> String { return "vCenter(\(percent))" }
225227
guard let layoutSuperview = layoutSuperview(context) else { return self }
226-
setVerticalCenter(percent.of(layoutSuperview.frame.height), context)
228+
setVerticalCenter((layoutSuperview.frame.height / 2) + percent.of(layoutSuperview.frame.height), context)
227229
return self
228230
}
229231

Tests/JustifyAlignSpec.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ class JustifyAlignSpec: QuickSpec {
8888
expect(_pinlayoutUnitTestLastWarning).to(contain(["justify", "center", "won't be applied", "left and right"]))
8989
}
9090

91-
it("test when hCenter has been set") {
91+
it("test when hCenter has been set and justify() won't be applied") {
9292
aView.pin.hCenter(60).justify(.center)
93-
expect(aView.frame).to(equal(CGRect(x: 10.0, y: 100.0, width: 100.0, height: 60.0)))
93+
expect(aView.frame).to(equal(CGRect(x: 210.0, y: 100.0, width: 100.0, height: 60.0)))
9494
expect(_pinlayoutUnitTestLastWarning).to(contain(["justify", "center", "won't be applied", "hCenter"]))
9595
}
9696
}
@@ -123,9 +123,9 @@ class JustifyAlignSpec: QuickSpec {
123123
expect(_pinlayoutUnitTestLastWarning).to(contain(["align(.center)", "won't be applied", "top and bottom"]))
124124
}
125125

126-
it("test when hCenter has been set") {
126+
it("test when hCenter has been set and align() won't be applied") {
127127
aView.pin.hCenter(60).align(.center)
128-
expect(aView.frame).to(equal(CGRect(x: 10.0, y: 100.0, width: 100.0, height: 60.0)))
128+
expect(aView.frame).to(equal(CGRect(x: 210.0, y: 100.0, width: 100.0, height: 60.0)))
129129
expect(_pinlayoutUnitTestLastWarning).to(contain(["align(.center)", "won't be applied", "top and bottom"]))
130130
}
131131
}

0 commit comments

Comments
 (0)