Skip to content

Commit c7eb48f

Browse files
committed
@UseAutoLayout
1 parent c356233 commit c7eb48f

File tree

8 files changed

+106
-2
lines changed

8 files changed

+106
-2
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
/*.xcodeproj
5+
xcuserdata/

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

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

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Boris Bielik
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Package.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// swift-tools-version:5.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "UseAutoLayout",
8+
products: [
9+
// Products define the executables and libraries produced by a package, and make them visible to other packages.
10+
.library(
11+
name: "UseAutoLayout",
12+
targets: ["UseAutoLayout"]),
13+
],
14+
targets: [
15+
.target(
16+
name: "UseAutoLayout",
17+
dependencies: [])
18+
]
19+
)

README.md

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,37 @@
1-
# UseAutoLayout
2-
UseAutoLayout @property wrapper for Swift
1+
# @UseAutoLayout
2+
Property wrapper that enables autolayout on applied views.
3+
4+
# Declaration:
5+
6+
`@UseAutoLayout` property wrapper
7+
8+
```
9+
@propertyWrapper
10+
public struct UseAutoLayout<T: UIView> {
11+
var value: T
12+
13+
public var wrappedValue: T {
14+
get { return value }
15+
set { self.value.translatesAutoresizingMaskIntoConstraints = false }
16+
}
17+
18+
public init(wrappedValue: T) {
19+
value = wrappedValue
20+
}
21+
}
22+
23+
```
24+
25+
# Usage
26+
27+
```
28+
@UseAutoLayout var label = UILabel()
29+
```
30+
31+
# Example
32+
33+
![Sample](assets/autolayout-1.png)
34+
35+
---
36+
37+
![](assets/autolayout-2.png)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#if canImport(UIKit)
2+
import UIKit
3+
4+
@propertyWrapper
5+
public struct UseAutoLayout<T: UIView> {
6+
var value: T
7+
8+
public var wrappedValue: T {
9+
get { return value }
10+
set { self.value.translatesAutoresizingMaskIntoConstraints = false }
11+
}
12+
13+
public init(wrappedValue: T) {
14+
value = wrappedValue
15+
}
16+
}
17+
#endif

assets/autolayout-1.png

1.19 MB
Loading

assets/autolayout-2.png

293 KB
Loading

0 commit comments

Comments
 (0)