Skip to content

Commit e5b0ae4

Browse files
authored
Merge pull request #141 from mirego/wrap_content
Add `wrapContent()` methods
2 parents df8c010 + d84b2a4 commit e5b0ae4

27 files changed

+905
-244
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ TestProjects/cocoapods/macos/PinLayout-macOS.xcworkspace/
1919
TestProjects/cocoapods/macos/Podfile.lock
2020
TestProjects/cocoapods/tvos/PinLayout-tvOS.xcworkspace/
2121
TestProjects/cocoapods/tvos/Podfile.lock
22+
2223
TestProjects/carthage/ios/Cartfile.resolved
2324
TestProjects/carthage/ios/Carthage/
2425

2526
TestProjects/swift-package-manager
2627

27-
Example/PinLayoutExampleMacOS
28+
Example/PinLayoutExampleMacOS

Example/.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ disabled_rules: # rule identifiers to exclude from running
2424

2525
excluded: # paths to ignore during linting. overridden by `included`.
2626
- Pods
27+
- PinLayoutExampleMacOS

Example/PinLayoutSample.xcodeproj/xcshareddata/xcschemes/PinLayoutSample.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

PinLayout.xcodeproj/project.pbxproj

Lines changed: 49 additions & 13 deletions
Large diffs are not rendered by default.

PinLayout.xcodeproj/xcshareddata/xcschemes/PinLayout-iOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

PinLayout.xcodeproj/xcshareddata/xcschemes/PinLayout-macOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0930"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

PinLayout.xcodeproj/xcshareddata/xcschemes/PinLayout-tvOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0900"
3+
LastUpgradeVersion = "0940"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

PinLayout.xcworkspace/contents.xcworkspacedata

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Nimble (7.0.3)
3-
- PinLayout (1.7.3)
3+
- PinLayout (1.7.4)
44
- Quick (1.2.0)
55
- Reveal-SDK (10)
66
- SwiftLint (0.25.1)
@@ -25,7 +25,7 @@ EXTERNAL SOURCES:
2525

2626
SPEC CHECKSUMS:
2727
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
28-
PinLayout: 04488e8fc8d19b59760bdf99a16deff7bfac422d
28+
PinLayout: e20545b1fd5110133e0b03bed61f196161af8b36
2929
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
3030
Reveal-SDK: 7869ddf1f902cabbb07a1f0dd06bd25861a126f7
3131
SwiftLint: ce933681be10c3266e82576dad676fa815a602e9

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Extremely Fast views layouting without auto layout. No magic, pure code, full co
3737
* Swift 3.2+ / Swift 4.0 / Objective-C
3838

3939
### 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+
4042
* :star: PinLayout now support macOS. See [macOS Support](#macos_support) for more information.
4143

4244
* :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
6163
* [Aspect Ratio](#aspect_ratio)
6264
* [Margins](#margins)
6365
* [safeAreaInsets support](#safeAreaInsets)
66+
* [WrapContent](#wrapCcontent)
6467
* [justify, align](#justify_align)
6568
* [UIView's transforms](#uiview_transform)
6669
* [Warnings](#warnings)
@@ -1134,8 +1137,65 @@ This example runs perfectly on a iPhone X (iOS 11), but it also runs on any devi
11341137

11351138
<br/>
11361139

1140+
<a name="wrapContent"></a>
1141+
## WrapContent
11371142

1138-
<a name="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.
1151+
* **`wrapContent(:WrapType)`**
1152+
**`wrapContent(:WrapType, padding: CGFloat)`** **`wrapContent(:WrapType, padding: UIEdgeInsets)`**
1153+
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.
1171+
Here is the initial state:
1172+
1173+
<img src="docs/images/wrapContent_before.png" width="200"/>
1174+
1175+
| Source code | Result | Description |
1176+
|---------------------|----------|-------------------|
1177+
| `view.pin.wrapContent()` | <img src="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)` | <img src="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)` | <img src="docs/images/wrapContent_horizontally.png" width="200"/> | Adjust only the view's width. |
1180+
| `view.pin.wrapContent(.vertically)` | <img src="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.
1185+
1186+
<img src="docs/images/wrapContent_example_1.png" width="540"/>
1187+
1188+
```swift
1189+
label.pin.below(of: imageView, aligned: .center).marginTop(4)
1190+
containerView.pin.wrapContent().center()
1191+
```
1192+
* 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).
1194+
1195+
<br/>
1196+
1197+
1198+
<a name="justify_align"></a>
11391199
## justify() / align()
11401200

11411201
**Methods:**

0 commit comments

Comments
 (0)