Skip to content

Commit d44d396

Browse files
author
Luc Dion
authored
Merge pull request #36 from mirego/fix_hCenter_vCenter
Fix an issue with `pin.vCenter()` and `pin.hCenter()`
2 parents e97ac71 + e44ae4a commit d44d396

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

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.0.6"
19+
s.version = "1.0.7"
2020
s.summary = "Swift manual views layouting without auto layout, no magic, pure code, full control. Concise syntax, readable & chainable."
2121

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

PinLayout/PinLayoutImpl.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class PinLayoutImpl: PinLayout {
157157
@discardableResult
158158
func hCenter() -> PinLayout {
159159
func context() -> String { return "hCenter()" }
160-
setHorizontalCenter(0, context)
160+
guard let layoutSuperview = layoutSuperview(context) else { return self }
161+
setHorizontalCenter(layoutSuperview.frame.width / 2, context)
161162
return self
162163
}
163164

@@ -179,7 +180,8 @@ class PinLayoutImpl: PinLayout {
179180
@discardableResult
180181
func vCenter() -> PinLayout {
181182
func context() -> String { return "vCenter()" }
182-
setVerticalCenter(0, context)
183+
guard let layoutSuperview = layoutSuperview(context) else { return self }
184+
setVerticalCenter(layoutSuperview.frame.height / 2, context)
183185
return self
184186
}
185187

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,17 @@ PinLayout also has shorter version that pins a view’s edge **directly** on its
193193
**Methods**:
194194

195195
* `top()`
196-
Position the view top edge directly on its superview top edge. Similar to calling top(0)
196+
Position the view top edge directly on its superview top edge. Similar to calling `top(0)`.
197197
* `left()`
198-
Position the view left edge directly on its superview top edge. Similar to calling left(0)
198+
Position the view left edge directly on its superview top edge. Similar to calling `left(0)`.
199199
* `bottom()`
200-
Position the view bottom edge directly on its superview top edge. Similar to calling bottom(0)
200+
Position the view bottom edge directly on its superview top edge. Similar to calling `bottom(0)`.
201201
* `right()`
202-
Position the view right edge directly on its superview top edge. Similar to calling right(0)
202+
Position the view right edge directly on its superview top edge. Similar to calling `right(0)`.
203203
* `hCenter()`
204-
Position the view horizontal center directly on its superview horizontal center. Similar to calling hCenter(0).
204+
Position the view horizontal center directly on its superview horizontal center. Similar to calling `hCenter(superview.frame.width / 2)`.
205205
* `vCenter()`
206-
Position the view vertical center directly on its superview vertical center. Similar to calling vCenter(0).
206+
Position the view vertical center directly on its superview vertical center. Similar to calling `hCenter(superview.frame.height / 2)`.
207207

208208
###### Usage examples:
209209
```javascript
@@ -778,6 +778,11 @@ Cell D:
778778

779779
<br>
780780

781+
## Coming soon <a name="coming_soon"></a>
782+
* minWidth/maxWidth, minHeight/maxHeight
783+
* CALayer support
784+
* ...
785+
781786

782787
## FAQ <a name="faq"></a>
783788

0 commit comments

Comments
 (0)