mortimer 21932aaaf0 a | 6 years ago | |
---|---|---|
.. | ||
PureLayout | 6 years ago | |
.DS_Store | 6 years ago | |
LICENSE | 6 years ago | |
README.md | 6 years ago |
The ultimate API for iOS & OS X Auto Layout — impressively simple, immensely powerful. PureLayout extends UIView
/NSView
, NSArray
, and NSLayoutConstraint
with a comprehensive Auto Layout API that is modeled after Apple's own frameworks. PureLayout is an Objective-C library that also works (and looks!) great with Swift using a bridging header.
Writing Auto Layout code from scratch isn't easy. PureLayout provides a fully capable and developer-friendly interface for Auto Layout. It is designed for clarity and simplicity, and takes inspiration from the AutoLayout UI options available in Interface Builder while delivering far more flexibility. The API is also highly efficient, as it adds only a thin layer of third party code and is engineered for maximum performance.
This is just a handy overview of the core API methods. Explore the header files for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes:
auto...
, which also makes it easy for Xcode to autocomplete as you type.relation:
parameter to make the constraint an inequality.PureLayout defines view attributes that are used to create auto layout constraints. Here is an illustration of the most common attributes.
There are 5 specific attribute types, which are used throughout most of the API:
ALEdge
ALDimension
ALAxis
ALMargin
available in iOS 8.0 and higher onlyALMarginAxis
available in iOS 8.0 and higher onlyAdditionally, there is one generic attribute type, ALAttribute
, which is effectively a union of all the specific types. You can think of this as the "supertype" of all of the specific attribute types, which means that it is always safe to cast a specific type to the generic ALAttribute
type. (Note that the reverse is not true -- casting a generic ALAttribute to a specific attribute type is unsafe!)
UIView
/NSView
+ autoCreateConstraintsWithoutInstalling:
+ autoSetPriority:forConstraints:
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only
- autoSetContent(CompressionResistance|Hugging)PriorityForAxis:
- autoCenterInSuperview:
- autoAlignAxisToSuperviewAxis:
- autoCenterInSuperviewMargins: // iOS 8.0+ only
- autoAlignAxisToSuperviewMarginAxis: // iOS 8.0+ only
- autoPinEdgeToSuperviewEdge:(withInset:)
- autoPinEdgesToSuperviewEdgesWithInsets:(excludingEdge:)
- autoPinEdgeToSuperviewMargin: // iOS 8.0+ only
- autoPinEdgesToSuperviewMargins(ExcludingEdge:) // iOS 8.0+ only
- autoPinEdge:toEdge:ofView:(withOffset:)
- autoAlignAxis:toSameAxisOfView:(withOffset:)
- autoMatchDimension:toDimension:ofView:(withOffset:|withMultiplier:)
- autoSetDimension(s)ToSize:
- autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:)
- autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS only
NSArray
// Arrays of Constraints
- autoInstallConstraints
- autoRemoveConstraints
- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only
// Arrays of Views
- autoAlignViewsToEdge:
- autoAlignViewsToAxis:
- autoMatchViewsDimension:
- autoSetViewsDimension:toSize:
- autoSetViewsDimensionsToSize:
- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:)
- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:)
NSLayoutConstraint
- autoInstall
- autoRemove
- autoIdentify: // iOS 7.0+, OS X 10.9+ only
Note: PureLayout requires a minimum deployment target of iOS 6.0 or OS X 10.7
Add the pod PureLayout
to your Podfile.
pod 'PureLayout'
Run pod install
from Terminal, then open your app's .xcworkspace
file to launch Xcode.
Import the PureLayout.h
header. Typically, this should be written as #import <PureLayout/PureLayout.h>
That's it - now go write some beautiful Auto Layout code!
Add the smileyborg/PureLayout
project to your Cartfile.
github "smileyborg/PureLayout"
Run carthage update
, then follow the additional steps required to add the iOS and/or Mac frameworks into your project.
Import the PureLayout framework/module (with the appropriate name for the platform you're using it on).
@import PureLayout_iOS
or @import PureLayout_Mac
#import <PureLayout_iOS/PureLayout_iOS.h>
or #import <PureLayout_Mac/PureLayout_Mac.h>
That's it - now go write some beautiful Auto Layout code!
PureLayout.h
header.That's it - now go write some beautiful Auto Layout code!
To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. Click here for more info.
Releases are tagged in the git commit history using semantic versioning. Check out the releases and release notes for each version.
Open the project included in the repository (requires Xcode 6 or higher). It contains iOS (Example-iOS
scheme) and OS X (Example-Mac
scheme) demos of the library being used in various scenarios.
On iOS, you can use different device simulators and rotate the device to see the constraints in action (as well as toggle the taller in-call status bar in the iOS Simulator).
On OS X, while running the app, press any key to cycle through the demos. You can resize the window to see the constraints in action.
Check out some Tips and Tricks to keep in mind when using the API.
An overview of the Auto Layout options available, ordered from the lowest- to highest-level of abstraction.
PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project.
Please open a new Issue here if you run into an issue, have a feature request, or want to share a comment. Note that general Auto Layout questions should be asked on Stack Overflow.
If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work.
Designed & maintained by Tyler Fox (@smileyborg). Distributed with the MIT license.