|
| 1 | +# AutoLayout |
| 2 | + |
| 3 | +A lightweight Swift library providing convenient Auto Layout helper methods for UIKit. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Easy-to-use methods for common layout tasks |
| 8 | +- Handles `translatesAutoresizingMaskIntoConstraints` automatically |
| 9 | +- Returns constraint references for further adjustments if needed |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +### Swift Package Manager |
| 14 | + |
| 15 | +You can add `AutoLayout` to your project using Swift Package Manager. In Xcode: |
| 16 | + |
| 17 | +1. Go to **File > Add Packages...** |
| 18 | +2. Enter the repository URL: `https://github.com/componentskit/AutoLayout` |
| 19 | +3. Choose the package and select **Add Package** |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +### Import the Library |
| 24 | + |
| 25 | +```swift |
| 26 | +import AutoLayout |
| 27 | +``` |
| 28 | + |
| 29 | +### Examples |
| 30 | + |
| 31 | +#### Constrain a View's Edges to Its Superview |
| 32 | + |
| 33 | +```swift |
| 34 | +let containerView = UIView() |
| 35 | +let subView = UIView() |
| 36 | + |
| 37 | +containerView.addSubview(subView) |
| 38 | +subView.allEdges(16) // Adds 16 padding on all sides |
| 39 | +``` |
| 40 | + |
| 41 | +#### Center a View Horizontally and Vertically |
| 42 | + |
| 43 | +```swift |
| 44 | +subView.centerHorizontally() |
| 45 | +subView.centerVertically() |
| 46 | +``` |
| 47 | + |
| 48 | +#### Set Width and Height |
| 49 | + |
| 50 | +```swift |
| 51 | +subView.width(100) |
| 52 | +subView.height(50) |
| 53 | +``` |
| 54 | + |
| 55 | +#### Position a View After Another View |
| 56 | + |
| 57 | +```swift |
| 58 | +let firstView = UIView() |
| 59 | +let secondView = UIView() |
| 60 | + |
| 61 | +containerView.addSubview(firstView) |
| 62 | +containerView.addSubview(secondView) |
| 63 | + |
| 64 | +secondView.after(firstView, padding: 8) |
| 65 | +``` |
| 66 | + |
| 67 | +#### Stretch a View Horizontally with Padding |
| 68 | + |
| 69 | +```swift |
| 70 | +subView.horizontally(20) |
| 71 | +``` |
| 72 | + |
| 73 | +## License |
| 74 | + |
| 75 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 76 | + |
| 77 | +## Contributing |
| 78 | + |
| 79 | +Contributions are welcome! Please open an issue or submit a pull request. |
0 commit comments