Latest | 0.0.2 |
---|---|
Homepage | https://github.com/alexliubj/EZAnchor |
License | MIT |
Platforms | ios 9.0, requires ARC |
Authors |
An easier way to code Autolayout
- [x] Are you annoyed of coding
.active = true
while using Autolayout Anchors over and over again? - [x] Are you annoyed of coding such long constraint sentence
refreshView.heightAnchor.constraint(equalToConstant: self.refreshViewHeight).isActive = true
over and over again?
Now EZAnchor
is definitely going to shorten your time of writing Autolayout Anchors by a simple installation.
Let’s see how it works:
- Anchor constraint to another anchor
//Traditional way viewA.leadingAnchor.constraint(equalTo: viewB.leadingAnchor).isActive = true
//With EZAnchor
viewA.leading == viewB.leading
* Anchor constraint to another anchor with constant
```swift
//Traditional way
viewA.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 10).isActive = true
//With EZAnchor
viewA.leading == self.view.leading + 10
- Anchor constraint to another anchor with negative constant
//Traditional way viewA.leadingAnchor.constraint(equalTo: viewB.leadingAnchor, constant: -10).isActive = true
//With EZAnchor
viewA.leading == viewB.leading – 10
* Anchor lessThanOrEqualTo another anchor
```swift
//Traditional way
viewA.leadingAnchor.constraint(lessThanOrEqualTo: viewB.leadingAnchor).isActive = true
//With EZAnchor
viewA.leading <= viewB.leading
- Anchor greaterThanOrEqualTo another anchor
viewA.leadingAnchor.constraint(greaterThanOrEqualTo: viewB.leadingAnchor).isActive = true
//With EZAnchor
viewA.leading >= viewB.leading
* Anchor lessThanOrEqualTo another anchor with constant
```swift
viewA.leadingAnchor.constraint(lessThanOrEqualTo: viewB.leadingAnchor, constant: 10).isActive = true
//With EZAnchor
viewA.leading <= viewB.leading + 10
- Anchor greaterThanOrEqualTo another anchor with constant
//Traditional way viewA.leadingAnchor.constraint(greaterThanOrEqualTo: viewB.leadingAnchor, constant: 10).isActive = true
//With EZAnchor
viewA.leading >= viewB.leading – 10
* Anchor equalTo another anchor with constant and multiplier
```swift
//Traditional way
viewA.heightAnchor.constraint(equalTo: viewB.heightAnchor, multiplier: 0.1, constant: -10).isActive = true
//With EZAnchor
viewA.height == viewB.height * 0.1 - 10
- Work with Priority
//With EZAnchor viewA.leading == (viewB.leading + 0.1) ^ .defaultLow
Installation
Drag and drop
Directly drag EZAnchor
and drop into your Xcode project.
CocoaPods
To integrate EZAnchor into your Xcode project using CocoaPods, specify it in your Podfile:
target 'MyApp' do
pod 'EZAnchor'
end
Carthage
To integrate EZAnchor into your Xcode project using Carthage, specify it in your Cartfile:
coming soon
Run carthage update to build the framework and drag the built EZAnchor.framework into your Xcode project.
Demo
You can easily implement the following layout with very simple and clean code:
//set viewA's layout constraints
viewA.backgroundColor = UIColor.red
viewA.width == 200
viewA.width == viewA.height
viewA.centerX == view.centerX
viewA.centerY == view.centerY
//set viewB's layout constraints
viewB.top == viewA.bottom + 20
viewB.width == viewA.width * 0.5
viewB.height == viewB.width - 10
viewB.centerX == viewA.centerX
Limitations
-
Better to have some basic concept of anchors, familiar with coding anchors programmatically. If not please learn from this link : Programmatically Creating Constraints!
- Avoid defining custom
UIControl
or view has same name withheight
orwidth
, there may have conflict withEZAnchor
library
Others
WTF Autolayout will help you debug autolayout complaints.
Logo is generated with Shopify logo maker
Inspired by: PureLayout Stevia layout
Todo
- [ ] Unit tests
- [ ] UI Tests
- [ ] CI
- [ ] Fastlane
License
This code and tool is under the MIT License.
Latest podspec
{ "name": "EZAnchor", "version": "0.0.2", "summary": "An easier way to code Autolayout.", "description": "An easier way to code Autolayoutn* Are you annoyed of coding `.active = true` while using Autolayout Anchors over and over again?n* Are you annoyed of coding such long constraint sentence `refreshView.heightAnchor.constraint(equalToConstant: self.refreshViewHeight).isActive = true` over and over again?n* Check the following elegant way to code Autolayout:n* viewA.leading == view.leadingn* viewA.leading == view.leading + 10n* viewA.height == view.height * 0.1 - 10n* viewA.leading == (view.leading + 0.1) ^ .defaultLow", "homepage": "https://github.com/alexliubj/EZAnchor", "screenshots": "https://raw.githubusercontent.com/alexliubj/EZAnchor/master/Logo.png", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Alex Liu": "[email protected]" }, "swift_version": "4.2", "platforms": { "ios": "9.0" }, "source": { "git": "https://github.com/alexliubj/EZAnchor.git", "tag": "0.0.2" }, "source_files": [ "Sources", "Sources/*.swift" ], "exclude_files": "", "requires_arc": true }
Wed, 13 Feb 2019 11:15:12 +0000