You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+61-1Lines changed: 61 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,8 @@ Extremely Fast views layouting without auto layout. No magic, pure code, full co
37
37
* Swift 3.2+ / Swift 4.0 / Objective-C
38
38
39
39
### Recent features
40
+
*:star: Add `wrapContent()` methods that adjust view's width and height to wrap all its subviews. See [wrapContent](#wrapContent) for more information.
41
+
40
42
*:star: PinLayout now support macOS. See [macOS Support](#macos_support) for more information.
41
43
42
44
*:star: PinLayout expose the `safeAreaInsets` through [`UIView.pin.safeArea`](#safeAreaInsets), this property support not only iOS 11, but is also backward compatible for earlier iOS releases (7/8/9/10). See [safeAreaInsets support](#safeAreaInsets) for more information.
@@ -61,6 +63,7 @@ Extremely Fast views layouting without auto layout. No magic, pure code, full co
61
63
*[Aspect Ratio](#aspect_ratio)
62
64
*[Margins](#margins)
63
65
*[safeAreaInsets support](#safeAreaInsets)
66
+
*[WrapContent](#wrapCcontent)
64
67
*[justify, align](#justify_align)
65
68
*[UIView's transforms](#uiview_transform)
66
69
*[Warnings](#warnings)
@@ -1134,8 +1137,65 @@ This example runs perfectly on a iPhone X (iOS 11), but it also runs on any devi
1134
1137
1135
1138
<br/>
1136
1139
1140
+
<aname="wrapContent"></a>
1141
+
## WrapContent
1137
1142
1138
-
<aname="aspect_ratio"></a>
1143
+
The following methods are useful to adjust view's width and/or height to wrap all its subviews. These methods also adjust subviews position to create a tight wrap.
1144
+
1145
+
**Methods:**
1146
+
1147
+
***`wrapContent()`**
1148
+
**`wrapContent(padding: CGFloat)`**
1149
+
**`wrapContent(padding: UIEdgeInsets)`**
1150
+
Adjust the view's width and height to wrap all its subviews. The method also adjusts subviews's position to create a tight wrap. It is also possible to specify an optional padding around all subviews.
Adjust the view's width AND/OR height to wrap all its subviews. Accept a WrapType parameter to define the wrapping type. It is also possible to specify an optional padding around all subviews.
1154
+
1155
+
**Types:**
1156
+
1157
+
***`WrapType`** values:
1158
+
* `.horizontally`: Adjust the view's width and update subviews's horizontal position.
1159
+
* `.vertically`: Adjust only the view's height and update subviews's vertical position.
1160
+
* `.all`: Adjust the view's width AND height and update subviews position. This is the default WrapType parameter value `wrapContent()` methods.
1161
+
1162
+
###### Usage examples:
1163
+
```swift
1164
+
view.pin.wrapContent().center() // wrap all subviews and centered the view inside its parent.
1165
+
view.pin.wrapContent(padding: 20) // wrap all subviews with a padding of 20 pixels all around
1166
+
view.pin.wrapContent(.horizontally)
1167
+
```
1168
+
1169
+
###### Example:
1170
+
This example show the result of different `wrapContent()` method calls.
|`view.pin.wrapContent()`| <imgsrc="docs/images/wrapContent_all.png"width="200"/> | Adjust the view's height and width to tight fit its subviews. |
1178
+
|`view.pin.wrapContent(padding: 10)`| <imgsrc="docs/images/wrapContent_padding.png"width="200"/> | Adjust the view's height and width and add a padding of 10 pixels around its subviews. |
1179
+
|`view.pin.wrapContent(.horizontally)`| <imgsrc="docs/images/wrapContent_horizontally.png"width="200"/> | Adjust only the view's width. |
1180
+
|`view.pin.wrapContent(.vertically)`| <imgsrc="docs/images/wrapContent_vertically.png"width="200"/> | Adjust only the view's height. |
1181
+
1182
+
1183
+
###### Example:
1184
+
This example shows how a view (`containerView`) with two subviews (`imageView` and `label`), can be adjusted to the size of its subviews and then centered inside its parent.
* Line 1: Position the label below the imageView aligned on its center with a top margin of 4 pixels.
1193
+
* Line 2: Adjust the `containerView`'s size and position its subviews to create a tight wrap around them, and then it center the `containerView` inside its parent (superview).
0 commit comments