Skip to content

Commit

Permalink
@UseAutoLayout
Browse files Browse the repository at this point in the history
  • Loading branch information
bielikb committed Sep 14, 2019
1 parent c356233 commit c7eb48f
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
7 changes: 7 additions & 0 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Boris Bielik

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// swift-tools-version:5.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "UseAutoLayout",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "UseAutoLayout",
targets: ["UseAutoLayout"]),
],
targets: [
.target(
name: "UseAutoLayout",
dependencies: [])
]
)
39 changes: 37 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,37 @@
# UseAutoLayout
UseAutoLayout @property wrapper for Swift
# @UseAutoLayout
Property wrapper that enables autolayout on applied views.

# Declaration:

`@UseAutoLayout` property wrapper

```
@propertyWrapper
public struct UseAutoLayout<T: UIView> {
var value: T
public var wrappedValue: T {
get { return value }
set { self.value.translatesAutoresizingMaskIntoConstraints = false }
}
public init(wrappedValue: T) {
value = wrappedValue
}
}
```

# Usage

```
@UseAutoLayout var label = UILabel()
```

# Example

![Sample](assets/autolayout-1.png)

---

![](assets/autolayout-2.png)
17 changes: 17 additions & 0 deletions Sources/UseAutoLayout/UseAutoLayout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if canImport(UIKit)
import UIKit

@propertyWrapper
public struct UseAutoLayout<T: UIView> {
var value: T

public var wrappedValue: T {
get { return value }
set { self.value.translatesAutoresizingMaskIntoConstraints = false }
}

public init(wrappedValue: T) {
value = wrappedValue
}
}
#endif
Binary file added assets/autolayout-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/autolayout-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c7eb48f

Please sign in to comment.