Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Deprecated in favor of PureLayout, which includes OS X support:

License

NotificationsYou must be signed in to change notification settings

smileyborg/UIView-AutoLayout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UIView+AutoLayout has been deprecated in favor ofPureLayout, which includes OS X support!

UIView+AutoLayoutBuild Status

The ultimate API for iOS Auto Layout -- impressively simple, immensely powerful. Comprised of categories onUIView,NSArray, andNSLayoutConstraint.

UIView+AutoLayout provides a developer-friendly interface for the vast majority of Auto Layout use cases. It is designed for clarity and simplicity, taking inspiration from the Auto Layout UI options available in Interface Builder but delivering far more flexibility and capability. The API is also highly efficient, as it adds only a thin layer of third party code and is engineered for maximum performance (for example, by automatically adding constraints to the nearest ancestor view).

API Cheat Sheet

This is just a handy overview of the core API methods. Check out theheader file for the full API and documentation. A couple notes:

  • All of the API methods begin withauto... for easy autocompletion!
  • All methods that generate constraints also automatically add the constraint(s) to the correct view, then return the newly created constraint(s) for you to optionally store for later adjustment or removal.
  • Many methods below also have a variant which includes arelation: parameter to make the constraint an inequality.

UIView

+ autoRemoveConstraint(s):- autoRemoveConstraintsAffectingView(AndSubviews)+ autoSetPriority:forConstraints:- autoSetContent(CompressionResistance|Hugging)PriorityForAxis:- autoCenterInSuperview:- autoAlignAxisToSuperviewAxis:- autoPinEdgeToSuperviewEdge:withInset:- autoPinEdgesToSuperviewEdges:withInsets:(excludingEdge:)- 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:

NSArray

- autoAlignViewsToEdge:- autoAlignViewsToAxis:- autoMatchViewsDimension:- autoSetViewsDimension:toSize:- autoDistributeViewsAlongAxis:withFixedSpacing:(insetSpacing:)alignment:- autoDistributeViewsAlongAxis:withFixedSize:(insetSpacing:)alignment:

NSLayoutConstraint

- autoInstall- autoRemove

Setup

Note: you must be developing for iOS 6.0 or later to use Auto Layout.

UsingCocoaPods

  1. Add the podUIView+AutoLayout to yourPodfile.

    pod 'UIView+AutoLayout'
  2. Runpod install from Terminal, then open your app's.xcworkspace file to launch Xcode.

  3. #import "UIView+AutoLayout.h" wherever you want to use the API.(Hint: adding the import to your precompiled header (.pch) file once will remove the need to import the .h file everywhere!)

That's it - now go write some beautifully simple Auto Layout code!

Manually from GitHub

  1. Download theUIView+AutoLayout.h andUIView+AutoLayout.m files in theSource directory.
  2. Add both files to your Xcode project.
  3. #import "UIView+AutoLayout.h" wherever you want to use the API.(Hint: adding the import to your precompiled header (.pch) file once will remove the need to import the .h file everywhere!)

That's it - now go write some beautifully simple Auto Layout code!

Releases

Releases are tagged in the git commit history usingsemantic versioning. Check out thereleases and release notes for each version.

Usage

Example Project

Check out theexample project included in the repository. It contains a few demos of the API in use for various scenarios. While running the app, tap on the screen to cycle through the demos. You can rotate the device to see the constraints in action (as well as toggle the taller in-call status bar in the iOS Simulator).

Tips and Tricks

Check out someTips and Tricks to keep in mind when using the API.

Limitations

  • May need to use theNSLayoutConstraint SDK API directly for some extremely uncommon use cases

UIView+AutoLayout vs. the rest

An overview of the Auto Layout options available, ordered from the lowest- to highest-level of abstraction.

  • AppleNSLayoutConstraint SDK API
    • Pros: Raw power
    • Cons: Extremely verbose, tedious to write, difficult to read
  • AppleVisual Format Language
    • Pros: Concise, convenient
    • Cons: Doesn't support some use cases, incomplete compile-time checks, must learn syntax, hard to debug
  • Apple Interface Builder
    • Pros: Visual, simple
    • Cons: Difficult for complex layouts, cannot dynamically set constraints at runtime, encourages hardcoded magic numbers, not always WYSIWYG
  • UIView+AutoLayout
    • Pros: Simple, efficient, built directly on the iOS SDK, minimal third party code
    • Cons: Not the most concise or pure expression of layout code
  • High-level layout frameworks (Masonry,KeepLayout)
    • Pros: Very clean, simple, and convenient
    • Cons: Heavy dependency on third party code, cannot mix with SDK APIs, potential compatibility issues with SDK changes, overloaded Objective-C syntax

Problems, Suggestions, Pull Requests?

Bring 'em on! :)

It's always a good idea to reach out before taking on any significant amount of changes or additions to the project. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work.

I'm especially interested in hearing about any common use cases that this API does not currently address. Feel free to add feature requests (and view current work in progress) on theFeature Requests page of the wiki for this project.

Meta

Designed & maintained by Tyler Fox (@smileyborg). Distributed with the MIT license.

About

Deprecated in favor of PureLayout, which includes OS X support:

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp