Merge pull request #1 from giuseppenucifora/sviluppo

Upgrade 0.3.0
This commit is contained in:
Giuseppe Nucifora 2015-08-18 15:36:38 +02:00
commit ae2f7ac8cd
227 changed files with 4817 additions and 2852 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "calendar_off.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "calendar_off@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "calendar_off@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "calendar_on.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "calendar_on@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "calendar_on@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

View File

@ -2,17 +2,17 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "price_on.png", "filename" : "location.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "price_on@2x.png", "filename" : "location@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "price_on@3x.png", "filename" : "location@3x.png",
"scale" : "3x" "scale" : "3x"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -2,17 +2,17 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "allergen_on.png", "filename" : "location_highlighted.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "allergen_on@2x.png", "filename" : "location_highlighted@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "allergen_on@3x.png", "filename" : "location_highlighted@3x.png",
"scale" : "3x" "scale" : "3x"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 502 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 998 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "location_off.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "location_off@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "location_off@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 927 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "location_on.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "location_on@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "location_on@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 927 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -2,17 +2,17 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "allergen_off.png", "filename" : "location_selected.png",
"scale" : "1x" "scale" : "1x"
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "allergen_off@2x.png", "filename" : "location_selected@2x.png",
"scale" : "2x" "scale" : "2x"
}, },
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "allergen_off@3x.png", "filename" : "location_selected@3x.png",
"scale" : "3x" "scale" : "3x"
} }
], ],

Binary file not shown.

After

Width:  |  Height:  |  Size: 817 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "price_off.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "price_off@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "price_off@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "type_off.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "type_off@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "type_off@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,23 +0,0 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "type_on.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "type_on@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "type_on@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 845 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -4,11 +4,17 @@ use_frameworks!
inhibit_all_warnings! inhibit_all_warnings!
pod 'PureLayout' pod 'PureLayout'
pod 'pop', '~> 1.0' pod 'pop', '~> 1.0'
pod 'UIActionSheet-Blocks'
pod 'UIAlertViewBlockExtension'
target 'TabBarPicker_Example', :exclusive => true do target 'TabBarPicker_Example', :exclusive => true do
pod "TabBarPicker", :path => "../" pod "TabBarPicker", :path => "../"
pod 'PureLayout' pod 'PureLayout'
pod 'pop', '~> 1.0' pod 'pop', '~> 1.0'
pod 'UIView-Overlay'
pod 'UIActionSheet-Blocks'
pod 'UIAlertViewBlockExtension'
end end
target 'TabBarPicker_Tests', :exclusive => true do target 'TabBarPicker_Tests', :exclusive => true do

View File

@ -1,12 +1,18 @@
PODS: PODS:
- pop (1.0.7) - pop (1.0.7)
- PureLayout (2.0.6) - PureLayout (3.0.0)
- TabBarPicker (0.1.0) - TabBarPicker (0.1.0)
- UIActionSheet-Blocks (1.0.1)
- UIAlertViewBlockExtension (1.0.1)
- UIView-Overlay (0.1)
DEPENDENCIES: DEPENDENCIES:
- pop (~> 1.0) - pop (~> 1.0)
- PureLayout - PureLayout
- TabBarPicker (from `../`) - TabBarPicker (from `../`)
- UIActionSheet-Blocks
- UIAlertViewBlockExtension
- UIView-Overlay
EXTERNAL SOURCES: EXTERNAL SOURCES:
TabBarPicker: TabBarPicker:
@ -14,7 +20,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
pop: 628ffc631644601567ee8bfaaaea493ebd7d0923 pop: 628ffc631644601567ee8bfaaaea493ebd7d0923
PureLayout: f25f0bb904d5ccfe6e31da3cb869185259f02e0d PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d
TabBarPicker: 0b8b0c04ad47ed9c740cef5d31cac7fefe6cb273 TabBarPicker: 0b8b0c04ad47ed9c740cef5d31cac7fefe6cb273
UIActionSheet-Blocks: a5781709d4c7e1bf81e0498caf187ab0535e5caf
UIAlertViewBlockExtension: b4b0a1e62c94170bacce519a2b16afbc81673714
UIView-Overlay: 95e42e733f6fdcfca523a399ba7907d0ca4570a0
COCOAPODS: 0.37.2 COCOAPODS: 0.38.2

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/Vendor/MMCPSScrollView/MMCPSScrollView.h

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/Vendor/NSString+HexColor/NSString+HexColor.h

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/Vendor/SharedLocationManager/SharedLocationManager.h

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/Vendor/UIButton+BackgroundColor/UIButton+BackgroundColor.h

View File

@ -0,0 +1 @@
../../../../../Pod/Classes/Vendor/UIButton+BackgroundColor/UIImage+Color.h

View File

@ -0,0 +1 @@
../../../UIActionSheet-Blocks/UIActionSheet+Blocks.h

View File

@ -0,0 +1 @@
../../../UIAlertViewBlockExtension/AlertViewExamples/UIAlertViewBlockExtension/AlertViewActionDispatcher.h

View File

@ -0,0 +1 @@
../../../UIAlertViewBlockExtension/AlertViewExamples/UIAlertViewBlockExtension/UIAlertView+BlockExtension.h

View File

@ -0,0 +1 @@
../../../UIView-Overlay/UIView+Overlay.h

View File

@ -1 +0,0 @@
../../../PureLayout/PureLayout/PureLayout/ALView+PureLayout.h

View File

@ -1 +0,0 @@
../../../PureLayout/PureLayout/PureLayout/NSArray+PureLayout.h

View File

@ -1 +0,0 @@
../../../PureLayout/PureLayout/PureLayout/NSLayoutConstraint+PureLayout.h

View File

@ -1 +0,0 @@
../../../PureLayout/PureLayout/PureLayout/PureLayout+Internal.h

View File

@ -1 +0,0 @@
../../../PureLayout/PureLayout/PureLayout/PureLayout.h

View File

@ -1 +0,0 @@
../../../PureLayout/PureLayout/PureLayout/PureLayoutDefines.h

View File

@ -1 +0,0 @@
../../../../../Pod/Classes/TabBarItem.h

View File

@ -1 +0,0 @@
../../../../../Pod/Classes/TabBarPicker.h

View File

@ -1 +0,0 @@
../../../../../Pod/Classes/TabBarPickerSubItemsView.h

View File

@ -1 +0,0 @@
../../../../../Pod/Classes/TabBarSubItem.h

View File

@ -1 +0,0 @@
../../../pop/pop/POP.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPAnimatableProperty.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPAnimation.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPAnimationEvent.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPAnimationExtras.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPAnimationTracer.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPAnimator.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPBasicAnimation.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPCustomAnimation.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPDecayAnimation.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPDefines.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPGeometry.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPLayerExtras.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPPropertyAnimation.h

View File

@ -1 +0,0 @@
../../../pop/pop/POPSpringAnimation.h

View File

@ -1,12 +1,18 @@
PODS: PODS:
- pop (1.0.7) - pop (1.0.7)
- PureLayout (2.0.6) - PureLayout (3.0.0)
- TabBarPicker (0.1.0) - TabBarPicker (0.1.0)
- UIActionSheet-Blocks (1.0.1)
- UIAlertViewBlockExtension (1.0.1)
- UIView-Overlay (0.1)
DEPENDENCIES: DEPENDENCIES:
- pop (~> 1.0) - pop (~> 1.0)
- PureLayout - PureLayout
- TabBarPicker (from `../`) - TabBarPicker (from `../`)
- UIActionSheet-Blocks
- UIAlertViewBlockExtension
- UIView-Overlay
EXTERNAL SOURCES: EXTERNAL SOURCES:
TabBarPicker: TabBarPicker:
@ -14,7 +20,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
pop: 628ffc631644601567ee8bfaaaea493ebd7d0923 pop: 628ffc631644601567ee8bfaaaea493ebd7d0923
PureLayout: f25f0bb904d5ccfe6e31da3cb869185259f02e0d PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d
TabBarPicker: 0b8b0c04ad47ed9c740cef5d31cac7fefe6cb273 TabBarPicker: 0b8b0c04ad47ed9c740cef5d31cac7fefe6cb273
UIActionSheet-Blocks: a5781709d4c7e1bf81e0498caf187ab0535e5caf
UIAlertViewBlockExtension: b4b0a1e62c94170bacce519a2b16afbc81673714
UIView-Overlay: 95e42e733f6fdcfca523a399ba7907d0ca4570a0
COCOAPODS: 0.37.2 COCOAPODS: 0.38.2

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "3CF761A949F3352DCFF7109B"
BuildableName = "TabBarPicker.framework"
BlueprintName = "TabBarPicker"
ReferencedContainer = "container:Pods.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<AdditionalOptions>
</AdditionalOptions>
<Testables>
</Testables>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -1,6 +1,5 @@
// //
// ALView+PureLayout.h // ALView+PureLayout.h
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2012 Richard Turton // Copyright (c) 2012 Richard Turton
@ -30,7 +29,9 @@
#import "PureLayoutDefines.h" #import "PureLayoutDefines.h"
#pragma mark - ALView+PureLayout __PL_ASSUME_NONNULL_BEGIN
#pragma mark ALView+PureLayout
/** /**
A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints. A category on UIView/NSView that provides a simple yet powerful interface for creating Auto Layout constraints.
@ -46,36 +47,14 @@
/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */ /** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */
- (instancetype)initForAutoLayout; - (instancetype)initForAutoLayout;
/** Configures an existing view to not convert the autoresizing mask into constraints and returns the view. */
#pragma mark Create Constraints Without Installing - (instancetype)configureForAutoLayout;
/** Prevents constraints created in the given constraints block from being automatically installed (activated).
The constraints created from calls to the PureLayout API in the block are returned in a single array. */
+ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block;
#pragma mark Set Priority For Constraints
/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block;
#pragma mark Set Identifier For Constraints
#if __PureLayout_MinBaseSDK_iOS_8_0
/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block;
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
#pragma mark Center & Align in Superview #pragma mark Center & Align in Superview
/** Centers the view in its superview. */ /** Centers the view in its superview. */
- (NSArray *)autoCenterInSuperview; - (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview;
/** Aligns the view to the same axis of its superview. */ /** Aligns the view to the same axis of its superview. */
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis; - (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
@ -83,7 +62,7 @@
#if __PureLayout_MinBaseSDK_iOS_8_0 #if __PureLayout_MinBaseSDK_iOS_8_0
/** Centers the view in its superview's margins. Available in iOS 8.0 and later. */ /** Centers the view in its superview's margins. Available in iOS 8.0 and later. */
- (NSArray *)autoCenterInSuperviewMargins; - (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins;
/** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */ /** Aligns the view to the corresponding margin axis of its superview. Available in iOS 8.0 and later. */
- (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis; - (NSLayoutConstraint *)autoAlignAxisToSuperviewMarginAxis:(ALAxis)axis;
@ -102,11 +81,14 @@
/** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */ /** Pins the given edge of the view to the same edge of its superview with an inset as a maximum or minimum. */
- (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation; - (NSLayoutConstraint *)autoPinEdgeToSuperviewEdge:(ALEdge)edge withInset:(CGFloat)inset relation:(NSLayoutRelation)relation;
/** Pins the edges of the view to the edges of its superview. */
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges;
/** Pins the edges of the view to the edges of its superview with the given edge insets. */ /** Pins the edges of the view to the edges of its superview with the given edge insets. */
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets; - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets;
/** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */ /** Pins 3 of the 4 edges of the view to the edges of its superview with the given edge insets, excluding one edge. */
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge; - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
#if __PureLayout_MinBaseSDK_iOS_8_0 #if __PureLayout_MinBaseSDK_iOS_8_0
@ -117,10 +99,10 @@
- (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation; - (NSLayoutConstraint *)autoPinEdgeToSuperviewMargin:(ALEdge)edge relation:(NSLayoutRelation)relation;
/** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */ /** Pins the edges of the view to the margins of its superview. Available in iOS 8.0 and later. */
- (NSArray *)autoPinEdgesToSuperviewMargins; - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins;
/** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */ /** Pins 3 of the 4 edges of the view to the margins of its superview excluding one edge. Available in iOS 8.0 and later. */
- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge; - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
@ -145,6 +127,9 @@
/** Aligns an axis of the view to the same axis of another view with an offset. */ /** Aligns an axis of the view to the same axis of another view with an offset. */
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset; - (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withOffset:(CGFloat)offset;
/** Aligns an axis of the view to the same axis of another view with a multiplier. */
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier;
#pragma mark Match Dimensions #pragma mark Match Dimensions
@ -167,7 +152,7 @@
#pragma mark Set Dimensions #pragma mark Set Dimensions
/** Sets the view to a specific size. */ /** Sets the view to a specific size. */
- (NSArray *)autoSetDimensionsToSize:(CGSize)size; - (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size;
/** Sets the given dimension of the view to a specific size. */ /** Sets the given dimension of the view to a specific size. */
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size; - (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size;
@ -179,11 +164,11 @@
#pragma mark Set Content Compression Resistance & Hugging #pragma mark Set Content Compression Resistance & Hugging
/** Sets the priority of content compression resistance for an axis. /** Sets the priority of content compression resistance for an axis.
NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis; - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis;
/** Sets the priority of content hugging for an axis. /** Sets the priority of content hugging for an axis.
NOTE: This method must be called from within the block passed into the method +[UIView autoSetPriority:forConstraints:] */ NOTE: This method must be called from within the block passed into the method +[NSLayoutConstraint autoSetPriority:forConstraints:] */
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis; - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis;
@ -223,31 +208,6 @@
#endif /* TARGET_OS_IPHONE */ #endif /* TARGET_OS_IPHONE */
#pragma mark Deprecated Methods
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Removes all explicit constraints that affect the view.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */
- (void)autoRemoveConstraintsAffectingView __attribute__((deprecated));
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Removes all constraints that affect the view, optionally including implicit constraints.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */
- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated));
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Recursively removes all explicit constraints that affect the view and its subviews.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove. */
- (void)autoRemoveConstraintsAffectingViewAndSubviews __attribute__((deprecated));
/** DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Recursively removes all constraints from the view and its subviews, optionally including implicit constraints.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
NOTE: Implicit constraints are auto-generated lower priority constraints, and you usually do not want to remove these. */
- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints __attribute__((deprecated));
@end @end
__PL_ASSUME_NONNULL_END

View File

@ -1,6 +1,5 @@
// //
// ALView+PureLayout.m // ALView+PureLayout.m
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2012 Richard Turton // Copyright (c) 2012 Richard Turton
@ -62,199 +61,15 @@
return self; return self;
} }
#pragma mark Create Constraints Without Installing
/** /**
A global variable that stores a stack of arrays of constraints created without being immediately installed. Configures an existing view to not convert the autoresizing mask into constraints and returns the view.
When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new
mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added
to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint
installation is prevented if this stack contains at least 1 array.
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
*/ */
static NSMutableArray *_al_arraysOfCreatedConstraints = nil; - (instancetype)configureForAutoLayout
/**
Accessor for the global state that stores arrays of constraints created without being installed.
*/
+ (NSMutableArray *)al_arraysOfCreatedConstraints
{ {
if (!_al_arraysOfCreatedConstraints) { self.translatesAutoresizingMaskIntoConstraints = NO;
_al_arraysOfCreatedConstraints = [NSMutableArray new]; return self;
}
return _al_arraysOfCreatedConstraints;
} }
/**
Accessor for the current mutable array of constraints created without being immediately installed.
*/
+ (NSMutableArray *)al_currentArrayOfCreatedConstraints
{
return [[self al_arraysOfCreatedConstraints] lastObject];
}
/**
Accessor for the global state that determines whether automatic constraint installation should be prevented.
*/
+ (BOOL)al_preventAutomaticConstraintInstallation
{
return [[self al_arraysOfCreatedConstraints] count] > 0;
}
/**
Prevents constraints created in the given constraints block from being automatically installed (activated).
The constraints created from calls to the PureLayout API in the block are returned in a single array.
@param block A block of method calls to the PureLayout API that create constraints.
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
*/
+ (NSArray *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block
{
NSAssert(block, @"The constraints block cannot be nil.");
NSArray *createdConstraints = nil;
if (block) {
[[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]];
block();
createdConstraints = [self al_currentArrayOfCreatedConstraints];
[[self al_arraysOfCreatedConstraints] removeLastObject];
}
return createdConstraints;
}
#pragma mark Set Priority For Constraints
/**
A global variable that stores a stack of layout priorities to set on constraints.
When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for
that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this
stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all
constraints created by this library (even if automatic constraint installation is being prevented).
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
*/
static NSMutableArray *_al_globalConstraintPriorities = nil;
/**
Accessor for the global stack of layout priorities.
*/
+ (NSMutableArray *)al_globalConstraintPriorities
{
if (!_al_globalConstraintPriorities) {
_al_globalConstraintPriorities = [NSMutableArray new];
}
return _al_globalConstraintPriorities;
}
/**
Returns the current layout priority to use for constraints.
When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return
the priority for the current block. Otherwise, the default Required priority is returned.
*/
+ (ALLayoutPriority)al_currentGlobalConstraintPriority
{
NSMutableArray *globalConstraintPriorities = [self al_globalConstraintPriorities];
if ([globalConstraintPriorities count] == 0) {
return ALLayoutPriorityRequired;
}
return [[globalConstraintPriorities lastObject] floatValue];
}
/**
Accessor for the global state that determines if we're currently in the scope of a priority constraints block.
*/
+ (BOOL)al_isExecutingPriorityConstraintsBlock
{
return [[self al_globalConstraintPriorities] count] > 0;
}
/**
Sets the constraint priority to the given value for all constraints created using the PureLayout
API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added
without using the PureLayout API!
@param priority The layout priority to be set on all constraints created in the constraints block.
@param block A block of method calls to the PureLayout API that create and install constraints.
*/
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block
{
NSAssert(block, @"The constraints block cannot be nil.");
if (block) {
[[self al_globalConstraintPriorities] addObject:@(priority)];
block();
[[self al_globalConstraintPriorities] removeLastObject];
}
}
#pragma mark Set Identifier For Constraints
#if __PureLayout_MinBaseSDK_iOS_8_0
/**
A global variable that stores a stack of identifier strings to set on constraints.
When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for
that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this
stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all
constraints created by this library (even if automatic constraint installation is being prevented).
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
*/
static NSMutableArray *_al_globalConstraintIdentifiers = nil;
/**
Accessor for the global state of constraint identifiers.
*/
+ (NSMutableArray *)al_globalConstraintIdentifiers
{
if (!_al_globalConstraintIdentifiers) {
_al_globalConstraintIdentifiers = [NSMutableArray new];
}
return _al_globalConstraintIdentifiers;
}
/**
Returns the current identifier string to use for constraints.
When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return
the identifier for the current block. Otherwise, nil is returned.
*/
+ (NSString *)al_currentGlobalConstraintIdentifier
{
NSMutableArray *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers];
if ([globalConstraintIdentifiers count] == 0) {
return nil;
}
return [globalConstraintIdentifiers lastObject];
}
/**
Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added
without using the PureLayout API!
@param identifier A string used to identify all constraints created in the constraints block.
@param block A block of method calls to the PureLayout API that create and install constraints.
*/
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block
{
NSAssert(block, @"The constraints block cannot be nil.");
NSAssert(identifier, @"The identifier string cannot be nil.");
if (block) {
if (identifier) {
[[self al_globalConstraintIdentifiers] addObject:identifier];
}
block();
if (identifier) {
[[self al_globalConstraintIdentifiers] removeLastObject];
}
}
}
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
#pragma mark Center in Superview #pragma mark Center in Superview
@ -263,9 +78,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoCenterInSuperview - (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
[constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]]; [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisHorizontal]];
[constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]]; [constraints addObject:[self autoAlignAxisToSuperviewAxis:ALAxisVertical]];
return constraints; return constraints;
@ -292,9 +107,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoCenterInSuperviewMargins - (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperviewMargins
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
[constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]]; [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisHorizontal]];
[constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]]; [constraints addObject:[self autoAlignAxisToSuperviewMarginAxis:ALAxisVertical]];
return constraints; return constraints;
@ -368,6 +183,16 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation]; return [self autoPinEdge:edge toEdge:edge ofView:superview withOffset:inset relation:relation];
} }
/**
Pins the edges of the view to the edges of its superview.
@return An array of constraints added.
*/
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdges
{
return [self autoPinEdgesToSuperviewEdgesWithInsets:ALEdgeInsetsZero];
}
/** /**
Pins the edges of the view to the edges of its superview with the given edge insets. Pins the edges of the view to the edges of its superview with the given edge insets.
The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint. The insets.left corresponds to a leading edge constraint, and insets.right corresponds to a trailing edge constraint.
@ -375,9 +200,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@param insets The insets for this view's edges from its superview's edges. @param insets The insets for this view's edges from its superview's edges.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:insets.left]];
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:insets.bottom]];
@ -394,9 +219,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
if (edge != ALEdgeTop) { if (edge != ALEdgeTop) {
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]]; [constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
} }
@ -454,9 +279,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoPinEdgesToSuperviewMargins - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMargins
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeLeading]];
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeBottom]];
@ -470,9 +295,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it. @param edge The edge of this view to exclude in pinning to its superview; this method will not apply any constraint to it.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge - (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
if (edge != ALEdgeTop) { if (edge != ALEdgeTop) {
[constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]]; [constraints addObject:[self autoPinEdgeToSuperviewMargin:ALEdgeTop]];
} }
@ -563,6 +388,19 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset]; return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withOffset:offset];
} }
/**
Aligns an axis of the view to the same axis of another view with a multiplier.
@param axis The axis of this view and the other view to align.
@param otherView The other view to align to. Must be in the same view hierarchy as this view.
@param multiplier The multiplier between the axis of this view and the axis of the other view.
@return The constraint added.
*/
- (NSLayoutConstraint *)autoAlignAxis:(ALAxis)axis toSameAxisOfView:(ALView *)otherView withMultiplier:(CGFloat)multiplier
{
return [self autoConstrainAttribute:(ALAttribute)axis toAttribute:(ALAttribute)axis ofView:otherView withMultiplier:multiplier];
}
#pragma mark Match Dimensions #pragma mark Match Dimensions
@ -646,9 +484,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
@param size The size to set this view's dimensions to. @param size The size to set this view's dimensions to.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoSetDimensionsToSize:(CGSize)size - (__NSArray_of(NSLayoutConstraint *) *)autoSetDimensionsToSize:(CGSize)size
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
[constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]]; [constraints addObject:[self autoSetDimension:ALDimensionWidth toSize:size.width]];
[constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]]; [constraints addObject:[self autoSetDimension:ALDimensionHeight toSize:size.height]];
return constraints; return constraints;
@ -694,14 +532,14 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
*/ */
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis - (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis
{ {
NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
if ([ALView al_isExecutingPriorityConstraintsBlock]) { if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
self.translatesAutoresizingMaskIntoConstraints = NO; self.translatesAutoresizingMaskIntoConstraints = NO;
ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
[self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis]; [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
#else #else
[self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; [self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
#endif /* TARGET_OS_IPHONE */ #endif /* TARGET_OS_IPHONE */
} }
} }
@ -714,14 +552,14 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
*/ */
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis - (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis
{ {
NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd)); NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
if ([ALView al_isExecutingPriorityConstraintsBlock]) { if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
self.translatesAutoresizingMaskIntoConstraints = NO; self.translatesAutoresizingMaskIntoConstraints = NO;
ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis]; ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
[self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis]; [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
#else #else
[self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis]; [self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
#endif /* TARGET_OS_IPHONE */ #endif /* TARGET_OS_IPHONE */
} }
} }
@ -884,100 +722,8 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
#endif /* TARGET_OS_IPHONE */ #endif /* TARGET_OS_IPHONE */
#pragma mark Deprecated Methods
/**
DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Removes all explicit constraints that affect the view.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead.
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove.
*/
- (void)autoRemoveConstraintsAffectingView
{
[self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:NO];
}
/**
DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Removes all constraints that affect the view, optionally including implicit constraints.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
It is not recommended to use this method to "reset" a view for reuse in a different way with new constraints. Create a new view instead.
NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at
its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these.
@param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped.
*/
- (void)autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints
{
NSMutableArray *constraintsToRemove = [NSMutableArray new];
ALView *startView = self;
do {
for (NSLayoutConstraint *constraint in startView.constraints) {
BOOL isImplicitConstraint = [NSStringFromClass([constraint class]) isEqualToString:@"NSContentSizeLayoutConstraint"];
if (shouldRemoveImplicitConstraints || !isImplicitConstraint) {
if (constraint.firstItem == self || constraint.secondItem == self) {
[constraintsToRemove addObject:constraint];
}
}
}
startView = startView.superview;
} while (startView);
[constraintsToRemove autoRemoveConstraints];
}
/**
DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Recursively removes all explicit constraints that affect the view and its subviews.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead.
NOTE: This method preserves implicit constraints, such as intrinsic content size constraints, which you usually do not want to remove.
*/
- (void)autoRemoveConstraintsAffectingViewAndSubviews
{
[self autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:NO];
}
/**
DEPRECATED as of PureLayout v2.0.0. Retain a reference to and remove specific constraints instead, or recreate the view(s) entirely to remove all constraints.
Recursively removes all constraints that affect the view and its subviews, optionally including implicit constraints.
WARNING: Apple's constraint solver is not optimized for large-scale constraint removal; you may encounter major performance issues after using this method.
It is not recommended to use this method to "reset" views for reuse in a different way with new constraints. Create a new view instead.
NOTE: Implicit constraints are auto-generated lower priority constraints (such as those that attempt to keep a view at
its intrinsic content size by hugging its content & resisting compression), and you usually do not want to remove these.
@param shouldRemoveImplicitConstraints Whether implicit constraints should be removed or skipped.
*/
- (void)autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:(BOOL)shouldRemoveImplicitConstraints
{
[self autoRemoveConstraintsAffectingViewIncludingImplicitConstraints:shouldRemoveImplicitConstraints];
for (ALView *subview in self.subviews) {
[subview autoRemoveConstraintsAffectingViewAndSubviewsIncludingImplicitConstraints:shouldRemoveImplicitConstraints];
}
}
#pragma mark Internal Methods #pragma mark Internal Methods
/**
Applies the global constraint priority and identifier to the given constraint.
This should be done before installing all constraints.
@param constraint The constraint to set the global priority and identifier on.
*/
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint
{
if ([ALView al_isExecutingPriorityConstraintsBlock]) {
constraint.priority = [ALView al_currentGlobalConstraintPriority];
}
#if __PureLayout_MinBaseSDK_iOS_8_0
NSString *globalConstraintIdentifier = [ALView al_currentGlobalConstraintIdentifier];
if (globalConstraintIdentifier) {
[constraint autoIdentify:globalConstraintIdentifier];
}
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
}
/** /**
Adds the given constraint to this view after applying the global state to the constraint. Adds the given constraint to this view after applying the global state to the constraint.
NOTE: This method is compatible with all versions of iOS, and should be used for older versions before the active NOTE: This method is compatible with all versions of iOS, and should be used for older versions before the active
@ -989,9 +735,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
*/ */
- (void)al_addConstraint:(NSLayoutConstraint *)constraint - (void)al_addConstraint:(NSLayoutConstraint *)constraint
{ {
[ALView al_applyGlobalStateToConstraint:constraint]; [NSLayoutConstraint al_applyGlobalStateToConstraint:constraint];
if ([ALView al_preventAutomaticConstraintInstallation]) { if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
[[ALView al_currentArrayOfCreatedConstraints] addObject:constraint]; [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:constraint];
} else { } else {
[self addConstraint:constraint]; [self addConstraint:constraint];
} }

View File

@ -1,6 +1,5 @@
// //
// NSArray+PureLayout.h // NSArray+PureLayout.h
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2012 Richard Turton // Copyright (c) 2012 Richard Turton
@ -30,7 +29,9 @@
#import "PureLayoutDefines.h" #import "PureLayoutDefines.h"
#pragma mark - NSArray+PureLayout __PL_ASSUME_NONNULL_BEGIN
#pragma mark NSArray+PureLayout
/** /**
A category on NSArray that provides a simple yet powerful interface to: A category on NSArray that provides a simple yet powerful interface to:
@ -48,60 +49,67 @@
/** Deactivates the constraints in this array. */ /** Deactivates the constraints in this array. */
- (void)autoRemoveConstraints; - (void)autoRemoveConstraints;
#if __PureLayout_MinBaseSDK_iOS_8_0 #if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
/** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */ /** Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. */
- (instancetype)autoIdentifyConstraints:(NSString *)identifier; - (instancetype)autoIdentifyConstraints:(NSString *)identifier;
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ #endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
#pragma mark Array of Views #pragma mark Array of Views
/** Aligns views in this array to one another along a given edge. */ /** Aligns views in this array to one another along a given edge. */
- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge; - (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge;
/** Aligns views in this array to one another along a given axis. */ /** Aligns views in this array to one another along a given axis. */
- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis; - (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis;
/** Matches a given dimension of all the views in this array. */ /** Matches a given dimension of all the views in this array. */
- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension; - (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension;
/** Sets the given dimension of all the views in this array to a given size. */ /** Sets the given dimension of all the views in this array to a given size. */
- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size; - (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size;
/** Sets all of the views in this array to a given size. */ /** Sets all of the views in this array to a given size. */
- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size; - (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size;
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */ /** Distributes the views in this array equally along the selected axis in their superview.
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them. */
alignedTo:(ALAttribute)alignment - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
withFixedSpacing:(CGFloat)spacing; alignedTo:(ALAttribute)alignment
withFixedSpacing:(CGFloat)spacing;
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */ /** Distributes the views in this array equally along the selected axis in their superview.
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis Views will be the same size (variable) in the dimension along the axis and will have spacing (fixed) between them, with optional insets from the first and last views to their superview. */
alignedTo:(ALAttribute)alignment - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
withFixedSpacing:(CGFloat)spacing alignedTo:(ALAttribute)alignment
insetSpacing:(BOOL)shouldSpaceInsets; withFixedSpacing:(CGFloat)spacing
insetSpacing:(BOOL)shouldSpaceInsets;
/** Distributes the views in this array equally along the selected axis in their superview. Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */ /** Distributes the views in this array equally along the selected axis in their superview.
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis Views will have spacing (fixed) between them, with optional insets from the first and last views to their superview, and optionally constrained to the same size in the dimension along the axis. */
alignedTo:(ALAttribute)alignment - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
withFixedSpacing:(CGFloat)spacing alignedTo:(ALAttribute)alignment
insetSpacing:(BOOL)shouldSpaceInsets withFixedSpacing:(CGFloat)spacing
matchedSizes:(BOOL)shouldMatchSizes; insetSpacing:(BOOL)shouldSpaceInsets
matchedSizes:(BOOL)shouldMatchSizes;
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */ /** Distributes the views in this array equally along the selected axis in their superview.
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them. */
alignedTo:(ALAttribute)alignment - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
withFixedSize:(CGFloat)size; alignedTo:(ALAttribute)alignment
withFixedSize:(CGFloat)size;
/** Distributes the views in this array equally along the selected axis in their superview. Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */ /** Distributes the views in this array equally along the selected axis in their superview.
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis Views will be the same size (fixed) in the dimension along the axis and will have spacing (variable) between them, with optional insets from the first and last views to their superview. */
alignedTo:(ALAttribute)alignment - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
withFixedSize:(CGFloat)size alignedTo:(ALAttribute)alignment
insetSpacing:(BOOL)shouldSpaceInsets; withFixedSize:(CGFloat)size
insetSpacing:(BOOL)shouldSpaceInsets;
@end @end
__PL_ASSUME_NONNULL_END

View File

@ -1,6 +1,5 @@
// //
// NSArray+PureLayout.m // NSArray+PureLayout.m
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2012 Richard Turton // Copyright (c) 2012 Richard Turton
@ -49,11 +48,11 @@
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) { if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) {
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[NSLayoutConstraint class]]) { if ([object isKindOfClass:[NSLayoutConstraint class]]) {
[ALView al_applyGlobalStateToConstraint:object]; [NSLayoutConstraint al_applyGlobalStateToConstraint:object];
} }
} }
if ([ALView al_preventAutomaticConstraintInstallation]) { if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
[[ALView al_currentArrayOfCreatedConstraints] addObjectsFromArray:self]; [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObjectsFromArray:self];
} else { } else {
[NSLayoutConstraint activateConstraints:self]; [NSLayoutConstraint activateConstraints:self];
} }
@ -87,7 +86,7 @@
} }
} }
#if __PureLayout_MinBaseSDK_iOS_8_0 #if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
/** /**
Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later. Sets the string as the identifier for the constraints in this array. Available in iOS 7.0 and OS X 10.9 and later.
@ -107,7 +106,7 @@
return self; return self;
} }
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ #endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
#pragma mark Array of Views #pragma mark Array of Views
@ -119,10 +118,10 @@
@param edge The edge to which the views will be aligned. @param edge The edge to which the views will be aligned.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoAlignViewsToEdge:(ALEdge)edge - (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToEdge:(ALEdge)edge
{ {
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
ALView *previousView = nil; ALView *previousView = nil;
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[ALView class]]) { if ([object isKindOfClass:[ALView class]]) {
@ -144,10 +143,10 @@
@param axis The axis to which the views will be aligned. @param axis The axis to which the views will be aligned.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis - (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis
{ {
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
ALView *previousView = nil; ALView *previousView = nil;
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[ALView class]]) { if ([object isKindOfClass:[ALView class]]) {
@ -169,10 +168,10 @@
@param dimension The dimension to match for all of the views. @param dimension The dimension to match for all of the views.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoMatchViewsDimension:(ALDimension)dimension - (__NSArray_of(NSLayoutConstraint *) *)autoMatchViewsDimension:(ALDimension)dimension
{ {
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views."); NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views.");
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
ALView *previousView = nil; ALView *previousView = nil;
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[ALView class]]) { if ([object isKindOfClass:[ALView class]]) {
@ -195,10 +194,10 @@
@param size The size to set the given dimension of each view to. @param size The size to set the given dimension of each view to.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size - (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimension:(ALDimension)dimension toSize:(CGFloat)size
{ {
NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view."); NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view.");
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[ALView class]]) { if ([object isKindOfClass:[ALView class]]) {
ALView *view = (ALView *)object; ALView *view = (ALView *)object;
@ -216,9 +215,9 @@
@param size The size to set each view's dimensions to. @param size The size to set each view's dimensions to.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoSetViewsDimensionsToSize:(CGSize)size - (__NSArray_of(NSLayoutConstraint *) *)autoSetViewsDimensionsToSize:(CGSize)size
{ {
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]]; [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionWidth toSize:size.width]];
[constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]]; [constraints addObjectsFromArray:[self autoSetViewsDimension:ALDimensionHeight toSize:size.height]];
return constraints; return constraints;
@ -235,9 +234,9 @@
@param spacing The fixed amount of spacing between each view. @param spacing The fixed amount of spacing between each view.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
alignedTo:(ALAttribute)alignment alignedTo:(ALAttribute)alignment
withFixedSpacing:(CGFloat)spacing withFixedSpacing:(CGFloat)spacing
{ {
return [self autoDistributeViewsAlongAxis:axis return [self autoDistributeViewsAlongAxis:axis
alignedTo:alignment alignedTo:alignment
@ -256,10 +255,10 @@
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
alignedTo:(ALAttribute)alignment alignedTo:(ALAttribute)alignment
withFixedSpacing:(CGFloat)spacing withFixedSpacing:(CGFloat)spacing
insetSpacing:(BOOL)shouldSpaceInsets insetSpacing:(BOOL)shouldSpaceInsets
{ {
return [self autoDistributeViewsAlongAxis:axis return [self autoDistributeViewsAlongAxis:axis
alignedTo:alignment alignedTo:alignment
@ -281,13 +280,13 @@
NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous! NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous!
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
alignedTo:(ALAttribute)alignment alignedTo:(ALAttribute)alignment
withFixedSpacing:(CGFloat)spacing withFixedSpacing:(CGFloat)spacing
insetSpacing:(BOOL)shouldSpaceInsets insetSpacing:(BOOL)shouldSpaceInsets
matchedSizes:(BOOL)shouldMatchSizes matchedSizes:(BOOL)shouldMatchSizes
{ {
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute.");
ALDimension matchedDimension; ALDimension matchedDimension;
ALEdge firstEdge, lastEdge; ALEdge firstEdge, lastEdge;
switch (axis) { switch (axis) {
@ -312,7 +311,7 @@
CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0; CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0;
CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0; CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0;
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
ALView *previousView = nil; ALView *previousView = nil;
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[ALView class]]) { if ([object isKindOfClass:[ALView class]]) {
@ -350,9 +349,9 @@
@param size The fixed size of each view in the dimension along the given axis. @param size The fixed size of each view in the dimension along the given axis.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
alignedTo:(ALAttribute)alignment alignedTo:(ALAttribute)alignment
withFixedSize:(CGFloat)size withFixedSize:(CGFloat)size
{ {
return [self autoDistributeViewsAlongAxis:axis return [self autoDistributeViewsAlongAxis:axis
alignedTo:alignment alignedTo:alignment
@ -371,12 +370,12 @@
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview. @param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
@return An array of constraints added. @return An array of constraints added.
*/ */
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis - (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
alignedTo:(ALAttribute)alignment alignedTo:(ALAttribute)alignment
withFixedSize:(CGFloat)size withFixedSize:(CGFloat)size
insetSpacing:(BOOL)shouldSpaceInsets insetSpacing:(BOOL)shouldSpaceInsets
{ {
NSAssert([self al_containsMinimumNumberOfViews:2], @"This array must contain at least 2 views to distribute."); NSAssert([self al_containsMinimumNumberOfViews:1], @"This array must contain at least 1 view to distribute.");
ALDimension fixedDimension; ALDimension fixedDimension;
NSLayoutAttribute attribute; NSLayoutAttribute attribute;
switch (axis) { switch (axis) {
@ -408,8 +407,8 @@
#endif /* TARGET_OS_IPHONE */ #endif /* TARGET_OS_IPHONE */
BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
NSMutableArray *constraints = [NSMutableArray new]; __NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
NSArray *views = [self al_copyViewsOnly]; __NSArray_of(ALView *) *views = [self al_copyViewsOnly];
NSUInteger numberOfViews = [views count]; NSUInteger numberOfViews = [views count];
ALView *commonSuperview = [views al_commonSuperviewOfViews]; ALView *commonSuperview = [views al_commonSuperviewOfViews];
ALView *previousView = nil; ALView *previousView = nil;
@ -443,7 +442,7 @@
#pragma mark Internal Helper Methods #pragma mark Internal Helper Methods
/** /**
Returns the common superview for the views in this array. Returns the common superview for the views in this array. If there is only one view in the array, its superview will be returned.
Raises an exception if the views in this array do not share a common superview. Raises an exception if the views in this array do not share a common superview.
@return The common superview for the views in this array. @return The common superview for the views in this array.
@ -458,7 +457,7 @@
if (previousView) { if (previousView) {
commonSuperview = [view al_commonSuperviewWithView:commonSuperview]; commonSuperview = [view al_commonSuperviewWithView:commonSuperview];
} else { } else {
commonSuperview = view; commonSuperview = view.superview;
} }
previousView = view; previousView = view;
} }
@ -492,9 +491,9 @@
@return A new array containing only the views that are in this array. @return A new array containing only the views that are in this array.
*/ */
- (NSArray *)al_copyViewsOnly - (__NSArray_of(ALView *) *)al_copyViewsOnly
{ {
NSMutableArray *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]]; __NSMutableArray_of(ALView *) *viewsOnlyArray = [NSMutableArray arrayWithCapacity:[self count]];
for (id object in self) { for (id object in self) {
if ([object isKindOfClass:[ALView class]]) { if ([object isKindOfClass:[ALView class]]) {
[viewsOnlyArray addObject:object]; [viewsOnlyArray addObject:object];

View File

@ -1,6 +1,5 @@
// //
// NSLayoutConstraint+PureLayout.h // NSLayoutConstraint+PureLayout.h
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2013-2015 Tyler Fox // Copyright (c) 2013-2015 Tyler Fox
@ -29,7 +28,9 @@
#import "PureLayoutDefines.h" #import "PureLayoutDefines.h"
#pragma mark - NSLayoutConstraint+PureLayout __PL_ASSUME_NONNULL_BEGIN
#pragma mark NSLayoutConstraint+PureLayout
/** /**
A category on NSLayoutConstraint that allows constraints to be easily installed & removed. A category on NSLayoutConstraint that allows constraints to be easily installed & removed.
@ -37,6 +38,39 @@
@interface NSLayoutConstraint (PureLayout) @interface NSLayoutConstraint (PureLayout)
#pragma mark Batch Constraint Creation
/** Creates all of the constraints in the block, then installs (activates) them all at once.
All constraints created from calls to the PureLayout API in the block are returned in a single array.
This may be more efficient than installing (activating) each constraint one-by-one. */
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block;
/** Creates all of the constraints in the block but prevents them from being automatically installed (activated).
All constraints created from calls to the PureLayout API in the block are returned in a single array. */
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block;
#pragma mark Set Priority For Constraints
/** Sets the constraint priority to the given value for all constraints created using the PureLayout API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added without using the PureLayout API! */
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block;
#pragma mark Identify Constraints
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
/** Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added without using the PureLayout API! */
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block;
/** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */
- (instancetype)autoIdentify:(NSString *)identifier;
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
#pragma mark Install & Remove Constraints #pragma mark Install & Remove Constraints
/** Activates the the constraint. */ /** Activates the the constraint. */
@ -45,14 +79,6 @@
/** Deactivates the constraint. */ /** Deactivates the constraint. */
- (void)autoRemove; - (void)autoRemove;
#pragma mark Identify Constraints
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
/** Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. */
- (instancetype)autoIdentify:(NSString *)identifier;
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
@end @end
__PL_ASSUME_NONNULL_END

View File

@ -1,6 +1,5 @@
// //
// NSLayoutConstraint+PureLayout.m // NSLayoutConstraint+PureLayout.m
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2013-2015 Tyler Fox // Copyright (c) 2013-2015 Tyler Fox
@ -28,6 +27,7 @@
#import "NSLayoutConstraint+PureLayout.h" #import "NSLayoutConstraint+PureLayout.h"
#import "ALView+PureLayout.h" #import "ALView+PureLayout.h"
#import "NSArray+PureLayout.h"
#import "PureLayout+Internal.h" #import "PureLayout+Internal.h"
@ -35,8 +35,250 @@
@implementation NSLayoutConstraint (PureLayout) @implementation NSLayoutConstraint (PureLayout)
#pragma mark Batch Constraint Creation
#pragma mark Installing & Removing Constraints /**
A global variable that stores a stack of arrays of constraints created without being immediately installed.
When executing a constraints block passed into the +[autoCreateConstraintsWithoutInstalling:] method, a new
mutable array is pushed onto this stack, and all constraints created with PureLayout in the block are added
to this array. When the block finishes executing, the array is popped off this stack. Automatic constraint
installation is prevented if this stack contains at least 1 array.
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
*/
static __NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *_al_arraysOfCreatedConstraints = nil;
/**
A global variable that is set to YES when installing a batch of constraints collected from a call to +[autoCreateAndInstallConstraints].
When this flag is YES, constraints are installed immediately without checking for or adding to the +[al_currentArrayOfCreatedConstraints].
This is necessary to properly handle nested calls to +[autoCreateAndInstallConstraints], where calls whose block contains other call(s)
should not return constraints from within the blocks of nested call(s).
*/
static BOOL _al_isInstallingCreatedConstraints = NO;
/**
Accessor for the global state that stores arrays of constraints created without being installed.
*/
+ (__NSMutableArray_of(__NSMutableArray_of(NSLayoutConstraint *) *) *)al_arraysOfCreatedConstraints
{
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
if (!_al_arraysOfCreatedConstraints) {
_al_arraysOfCreatedConstraints = [NSMutableArray new];
}
return _al_arraysOfCreatedConstraints;
}
/**
Accessor for the current mutable array of constraints created without being immediately installed.
*/
+ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints
{
return [[self al_arraysOfCreatedConstraints] lastObject];
}
/**
Accessor for the global state that determines whether automatic constraint installation should be prevented.
*/
+ (BOOL)al_preventAutomaticConstraintInstallation
{
return (_al_isInstallingCreatedConstraints == NO) && ([[self al_arraysOfCreatedConstraints] count] > 0);
}
/**
Creates all of the constraints in the block, then installs (activates) them all at once.
All constraints created from calls to the PureLayout API in the block are returned in a single array.
This may be more efficient than installing (activating) each constraint one-by-one.
Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints
created in nested calls; constraints are only returned from the inner-most call they are created within.
@param block A block of method calls to the PureLayout API that create constraints.
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
*/
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateAndInstallConstraints:(ALConstraintsBlock)block
{
NSArray *createdConstraints = [self autoCreateConstraintsWithoutInstalling:block];
_al_isInstallingCreatedConstraints = YES;
[createdConstraints autoInstallConstraints];
_al_isInstallingCreatedConstraints = NO;
return createdConstraints;
}
/**
Creates all of the constraints in the block but prevents them from being automatically installed (activated).
All constraints created from calls to the PureLayout API in the block are returned in a single array.
Note: calls to this method may be nested. The constraints returned from a call will NOT include constraints
created in nested calls; constraints are only returned from the inner-most call they are created within.
@param block A block of method calls to the PureLayout API that create constraints.
@return An array of the constraints that were created from calls to the PureLayout API inside the block.
*/
+ (__NSArray_of(NSLayoutConstraint *) *)autoCreateConstraintsWithoutInstalling:(ALConstraintsBlock)block
{
NSAssert(block, @"The constraints block cannot be nil.");
NSArray *createdConstraints = nil;
if (block) {
[[self al_arraysOfCreatedConstraints] addObject:[NSMutableArray new]];
block();
createdConstraints = [self al_currentArrayOfCreatedConstraints];
[[self al_arraysOfCreatedConstraints] removeLastObject];
}
return createdConstraints;
}
#pragma mark Set Priority For Constraints
/**
A global variable that stores a stack of layout priorities to set on constraints.
When executing a constraints block passed into the +[autoSetPriority:forConstraints:] method, the priority for
that call is pushed onto this stack, and when the block finishes executing, that priority is popped off this
stack. If this stack contains at least 1 priority, the priority at the top of the stack will be set for all
constraints created by this library (even if automatic constraint installation is being prevented).
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
*/
static __NSMutableArray_of(NSNumber *) *_al_globalConstraintPriorities = nil;
/**
Accessor for the global stack of layout priorities.
*/
+ (__NSMutableArray_of(NSNumber *) *)al_globalConstraintPriorities
{
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
if (!_al_globalConstraintPriorities) {
_al_globalConstraintPriorities = [NSMutableArray new];
}
return _al_globalConstraintPriorities;
}
/**
Returns the current layout priority to use for constraints.
When executing a constraints block passed into +[autoSetPriority:forConstraints:], this will return
the priority for the current block. Otherwise, the default Required priority is returned.
*/
+ (ALLayoutPriority)al_currentGlobalConstraintPriority
{
__NSMutableArray_of(NSNumber *) *globalConstraintPriorities = [self al_globalConstraintPriorities];
if ([globalConstraintPriorities count] == 0) {
return ALLayoutPriorityRequired;
}
return [[globalConstraintPriorities lastObject] floatValue];
}
/**
Accessor for the global state that determines if we're currently in the scope of a priority constraints block.
*/
+ (BOOL)al_isExecutingPriorityConstraintsBlock
{
return [[self al_globalConstraintPriorities] count] > 0;
}
/**
Sets the constraint priority to the given value for all constraints created using the PureLayout
API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the priority) on constraints created or added
without using the PureLayout API!
@param priority The layout priority to be set on all constraints created in the constraints block.
@param block A block of method calls to the PureLayout API that create and install constraints.
*/
+ (void)autoSetPriority:(ALLayoutPriority)priority forConstraints:(ALConstraintsBlock)block
{
NSAssert(block, @"The constraints block cannot be nil.");
if (block) {
[[self al_globalConstraintPriorities] addObject:@(priority)];
block();
[[self al_globalConstraintPriorities] removeLastObject];
}
}
#pragma mark Identify Constraints
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
/**
A global variable that stores a stack of identifier strings to set on constraints.
When executing a constraints block passed into the +[autoSetIdentifier:forConstraints:] method, the identifier for
that call is pushed onto this stack, and when the block finishes executing, that identifier is popped off this
stack. If this stack contains at least 1 identifier, the identifier at the top of the stack will be set for all
constraints created by this library (even if automatic constraint installation is being prevented).
NOTE: Access to this variable is not synchronized (and should only be done on the main thread).
*/
static __NSMutableArray_of(NSString *) *_al_globalConstraintIdentifiers = nil;
/**
Accessor for the global state of constraint identifiers.
*/
+ (__NSMutableArray_of(NSString *) *)al_globalConstraintIdentifiers
{
NSAssert([NSThread isMainThread], @"PureLayout is not thread safe, and must be used exclusively from the main thread.");
if (!_al_globalConstraintIdentifiers) {
_al_globalConstraintIdentifiers = [NSMutableArray new];
}
return _al_globalConstraintIdentifiers;
}
/**
Returns the current identifier string to use for constraints.
When executing a constraints block passed into +[autoSetIdentifier:forConstraints:], this will return
the identifier for the current block. Otherwise, nil is returned.
*/
+ (NSString *)al_currentGlobalConstraintIdentifier
{
__NSMutableArray_of(NSString *) *globalConstraintIdentifiers = [self al_globalConstraintIdentifiers];
if ([globalConstraintIdentifiers count] == 0) {
return nil;
}
return [globalConstraintIdentifiers lastObject];
}
/**
Sets the identifier for all constraints created using the PureLayout API within the given constraints block.
NOTE: This method will have no effect (and will NOT set the identifier) on constraints created or added
without using the PureLayout API!
@param identifier A string used to identify all constraints created in the constraints block.
@param block A block of method calls to the PureLayout API that create and install constraints.
*/
+ (void)autoSetIdentifier:(NSString *)identifier forConstraints:(ALConstraintsBlock)block
{
NSAssert(block, @"The constraints block cannot be nil.");
NSAssert(identifier, @"The identifier string cannot be nil.");
if (block) {
if (identifier) {
[[self al_globalConstraintIdentifiers] addObject:identifier];
}
block();
if (identifier) {
[[self al_globalConstraintIdentifiers] removeLastObject];
}
}
}
/**
Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later.
The identifier will be printed along with the constraint's description.
This is helpful to document a constraint's purpose and aid in debugging.
@param identifier A string used to identify this constraint.
@return This constraint.
*/
- (instancetype)autoIdentify:(NSString *)identifier
{
if ([self respondsToSelector:@selector(setIdentifier:)]) {
self.identifier = identifier;
}
return self;
}
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
#pragma mark Install & Remove Constraints
/** /**
Activates the constraint. Activates the constraint.
@ -45,9 +287,9 @@
{ {
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 #if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
if ([self respondsToSelector:@selector(setActive:)]) { if ([self respondsToSelector:@selector(setActive:)]) {
[ALView al_applyGlobalStateToConstraint:self]; [NSLayoutConstraint al_applyGlobalStateToConstraint:self];
if ([ALView al_preventAutomaticConstraintInstallation]) { if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
[[ALView al_currentArrayOfCreatedConstraints] addObject:self]; [[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:self];
} else { } else {
self.active = YES; self.active = YES;
} }
@ -101,30 +343,26 @@
} }
#pragma mark Identify Constraints #pragma mark Internal Methods
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
/** /**
Sets the string as the identifier for this constraint. Available in iOS 7.0 and OS X 10.9 and later. Applies the global constraint priority and identifier to the given constraint.
The identifier will be printed along with the constraint's description. This should be done before installing all constraints.
This is helpful to document a constraint's purpose and aid in debugging.
@param identifier A string used to identify this constraint. @param constraint The constraint to set the global priority and identifier on.
@return This constraint.
*/ */
- (instancetype)autoIdentify:(NSString *)identifier + (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint
{ {
if ([self respondsToSelector:@selector(setIdentifier:)]) { if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
self.identifier = identifier; constraint.priority = [NSLayoutConstraint al_currentGlobalConstraintPriority];
}
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
NSString *globalConstraintIdentifier = [NSLayoutConstraint al_currentGlobalConstraintIdentifier];
if (globalConstraintIdentifier) {
[constraint autoIdentify:globalConstraintIdentifier];
} }
return self;
}
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */ #endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
}
#pragma mark Internal Methods
/** /**
Returns the corresponding NSLayoutAttribute for the given ALAttribute. Returns the corresponding NSLayoutAttribute for the given ALAttribute.
@ -234,7 +472,7 @@
break; break;
default: default:
NSAssert(nil, @"Not a valid ALAxis."); NSAssert(nil, @"Not a valid ALAxis.");
constraintAxis = ALLayoutConstraintAxisHorizontal; // default to a random value to satisfy the compiler constraintAxis = ALLayoutConstraintAxisHorizontal; // default to an arbitrary value to satisfy the compiler
break; break;
} }
return constraintAxis; return constraintAxis;
@ -273,7 +511,7 @@
break; break;
default: default:
NSAssert(nil, @"Not a valid ALEdge."); NSAssert(nil, @"Not a valid ALEdge.");
margin = ALMarginLeft; // default to a random value to satisfy the compiler margin = ALMarginLeft; // default to an arbitrary value to satisfy the compiler
break; break;
} }
return margin; return margin;
@ -299,11 +537,11 @@
case ALAxisBaseline: case ALAxisBaseline:
case ALAxisFirstBaseline: case ALAxisFirstBaseline:
NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes."); NSAssert(nil, @"The baseline axis attributes do not have corresponding margin axis attributes.");
marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler
break; break;
default: default:
NSAssert(nil, @"Not a valid ALAxis."); NSAssert(nil, @"Not a valid ALAxis.");
marginAxis = ALMarginAxisVertical; // default to a random value to satisfy the compiler marginAxis = ALMarginAxisVertical; // default to an arbitrary value to satisfy the compiler
break; break;
} }
return marginAxis; return marginAxis;

View File

@ -1,6 +1,5 @@
// //
// PureLayout+Internal.h // PureLayout+Internal.h
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2014-2015 Tyler Fox // Copyright (c) 2014-2015 Tyler Fox
@ -28,9 +27,15 @@
#import "PureLayoutDefines.h" #import "PureLayoutDefines.h"
// Using generics with NSMutableArray is so common in the internal implementation of PureLayout that it gets a dedicated preprocessor macro for better readability.
#define __NSMutableArray_of(type) __PL_GENERICS(NSMutableArray, type)
__PL_ASSUME_NONNULL_BEGIN
/** A constant that represents the smallest valid positive value for the multiplier of a constraint, /** A constant that represents the smallest valid positive value for the multiplier of a constraint,
since a value of 0 will cause the second item to be lost in the internal auto layout engine. */ since a value of 0 will cause the second item to be lost in the internal auto layout engine. */
static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems static const CGFloat kMULTIPLIER_MIN_VALUE = (CGFloat)0.00001; // very small floating point numbers (e.g. CGFLOAT_MIN) can cause problems
/** /**
@ -38,12 +43,6 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi
*/ */
@interface ALView (PureLayoutInternal) @interface ALView (PureLayoutInternal)
+ (BOOL)al_preventAutomaticConstraintInstallation;
+ (NSMutableArray *)al_currentArrayOfCreatedConstraints;
+ (BOOL)al_isExecutingPriorityConstraintsBlock;
+ (ALLayoutPriority)al_currentGlobalConstraintPriority;
+ (NSString *)al_currentGlobalConstraintIdentifier;
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint;
- (void)al_addConstraint:(NSLayoutConstraint *)constraint; - (void)al_addConstraint:(NSLayoutConstraint *)constraint;
- (ALView *)al_commonSuperviewWithView:(ALView *)otherView; - (ALView *)al_commonSuperviewWithView:(ALView *)otherView;
- (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis; - (NSLayoutConstraint *)al_alignAttribute:(ALAttribute)attribute toView:(ALView *)otherView forAxis:(ALAxis)axis;
@ -58,7 +57,7 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi
- (ALView *)al_commonSuperviewOfViews; - (ALView *)al_commonSuperviewOfViews;
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews; - (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews;
- (NSArray *)al_copyViewsOnly; - (__NSArray_of(ALView *) *)al_copyViewsOnly;
@end @end
@ -68,6 +67,14 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi
*/ */
@interface NSLayoutConstraint (PureLayoutInternal) @interface NSLayoutConstraint (PureLayoutInternal)
+ (BOOL)al_preventAutomaticConstraintInstallation;
+ (__NSMutableArray_of(NSLayoutConstraint *) *)al_currentArrayOfCreatedConstraints;
+ (BOOL)al_isExecutingPriorityConstraintsBlock;
+ (ALLayoutPriority)al_currentGlobalConstraintPriority;
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
+ (NSString *)al_currentGlobalConstraintIdentifier;
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint;
+ (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute; + (NSLayoutAttribute)al_layoutAttributeForAttribute:(ALAttribute)attribute;
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis; + (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis;
#if __PureLayout_MinBaseSDK_iOS_8_0 #if __PureLayout_MinBaseSDK_iOS_8_0
@ -76,3 +83,5 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
@end @end
__PL_ASSUME_NONNULL_END

View File

@ -1,6 +1,5 @@
// //
// PureLayout.h // PureLayout.h
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2014-2015 Tyler Fox // Copyright (c) 2014-2015 Tyler Fox
@ -29,6 +28,14 @@
#ifndef PureLayout_h #ifndef PureLayout_h
#define PureLayout_h #define PureLayout_h
#import <Foundation/Foundation.h>
//! Project version number for PureLayout.
FOUNDATION_EXPORT double PureLayoutVersionNumber;
//! Project version string for PureLayout.
FOUNDATION_EXPORT const unsigned char PureLayoutVersionString[];
#import "ALView+PureLayout.h" #import "ALView+PureLayout.h"
#import "NSArray+PureLayout.h" #import "NSArray+PureLayout.h"
#import "NSLayoutConstraint+PureLayout.h" #import "NSLayoutConstraint+PureLayout.h"

View File

@ -1,6 +1,5 @@
// //
// PureLayoutDefines.h // PureLayoutDefines.h
// v2.0.5
// https://github.com/smileyborg/PureLayout // https://github.com/smileyborg/PureLayout
// //
// Copyright (c) 2014-2015 Tyler Fox // Copyright (c) 2014-2015 Tyler Fox
@ -40,7 +39,26 @@
#define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) #define __PureLayout_MinSysVer_iOS_8_0 (TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
#define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4) #define __PureLayout_MinSysVer_OSX_10_9 (!TARGET_OS_IPHONE && floor(NSFoundationVersionNumber) > NSFoundationVersionNumber10_8_4)
// Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent // Define some preprocessor macros that allow nullability annotations to be adopted in a backwards-compatible manner.
#if __has_feature(nullability)
# define __PL_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
# define __PL_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
#else
# define __PL_ASSUME_NONNULL_BEGIN
# define __PL_ASSUME_NONNULL_END
#endif
// Define some preprocessor macros that allow generics to be adopted in a backwards-compatible manner.
#if __has_feature(objc_generics)
# define __PL_GENERICS(class, ...) class<__VA_ARGS__>
#else
# define __PL_GENERICS(class, ...) class
#endif
// Using generics with NSArray is so common in PureLayout that it gets a dedicated preprocessor macro for better readability.
#define __NSArray_of(type) __PL_GENERICS(NSArray, type)
// Define generic AL-prefixed macros for the types/constants/etc that have slight naming variations across iOS and OS X, which allows the same code to be platform-independent.
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
# import <UIKit/UIKit.h> # import <UIKit/UIKit.h>
# define ALView UIView # define ALView UIView
@ -108,9 +126,9 @@ typedef NS_ENUM(NSInteger, ALDimension) {
/** Constants that represent axes of a view. */ /** Constants that represent axes of a view. */
typedef NS_ENUM(NSInteger, ALAxis) { typedef NS_ENUM(NSInteger, ALAxis) {
/** A vertical line through the middle of the view's left and right edges. */ /** A vertical line equidistant from the view's left and right edges. */
ALAxisVertical = NSLayoutAttributeCenterX, ALAxisVertical = NSLayoutAttributeCenterX,
/** A horizontal line through the middle of the view's top and bottom edges. */ /** A horizontal line equidistant from the view's top and bottom edges. */
ALAxisHorizontal = NSLayoutAttributeCenterY, ALAxisHorizontal = NSLayoutAttributeCenterY,
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
@ -143,9 +161,9 @@ typedef NS_ENUM(NSInteger, ALMargin) {
/** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */ /** Constants that represent axes of the layout margins of a view. Available in iOS 8.0 and later. */
typedef NS_ENUM(NSInteger, ALMarginAxis) { typedef NS_ENUM(NSInteger, ALMarginAxis) {
/** A vertical line through the middle of the view's left and right margins. */ /** A vertical line equidistant from the view's left and right margins. */
ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins, ALMarginAxisVertical = NSLayoutAttributeCenterXWithinMargins,
/** A horizontal line through the middle of the view's top and bottom margins. */ /** A horizontal line equidistant from the view's top and bottom margins. */
ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins ALMarginAxisHorizontal = NSLayoutAttributeCenterYWithinMargins
}; };
@ -170,9 +188,9 @@ typedef NS_ENUM(NSInteger, ALAttribute) {
ALAttributeWidth = ALDimensionWidth, ALAttributeWidth = ALDimensionWidth,
/** The height of the view. */ /** The height of the view. */
ALAttributeHeight = ALDimensionHeight, ALAttributeHeight = ALDimensionHeight,
/** A vertical line through the middle of the view's left and right edges. */ /** A vertical line equidistant from the view's left and right edges. */
ALAttributeVertical = ALAxisVertical, ALAttributeVertical = ALAxisVertical,
/** A horizontal line through the middle of the view's top and bottom edges. */ /** A horizontal line equidistant from the view's top and bottom edges. */
ALAttributeHorizontal = ALAxisHorizontal, ALAttributeHorizontal = ALAxisHorizontal,
/** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */ /** A horizontal line at the baseline of the last line of text in the view. (For views that do not draw text, will be equivalent to ALEdgeBottom.) Same as ALAxisLastBaseline. */
ALAttributeBaseline = ALAxisBaseline, ALAttributeBaseline = ALAxisBaseline,
@ -193,9 +211,9 @@ typedef NS_ENUM(NSInteger, ALAttribute) {
ALAttributeMarginLeading = ALMarginLeading, ALAttributeMarginLeading = ALMarginLeading,
/** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */ /** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
ALAttributeMarginTrailing = ALMarginTrailing, ALAttributeMarginTrailing = ALMarginTrailing,
/** A vertical line through the middle of the view's left and right margins. */ /** A vertical line equidistant from the view's left and right margins. */
ALAttributeMarginAxisVertical = ALMarginAxisVertical, ALAttributeMarginAxisVertical = ALMarginAxisVertical,
/** A horizontal line through the middle of the view's top and bottom margins. */ /** A horizontal line equidistant from the view's top and bottom margins. */
ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal ALAttributeMarginAxisHorizontal = ALMarginAxisHorizontal
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */ #endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
}; };

View File

@ -1,16 +1,87 @@
# [![PureLayout](https://github.com/smileyborg/PureLayout/blob/master/Images/PureLayout.png?raw=true)](#) # [![PureLayout](https://github.com/smileyborg/PureLayout/blob/master/Images/PureLayout.png?raw=true)](#)
[![Build Status](http://img.shields.io/travis/smileyborg/PureLayout.svg?style=flat)](https://travis-ci.org/smileyborg/PureLayout) [![Test Coverage](http://img.shields.io/coveralls/smileyborg/PureLayout.svg?style=flat)](https://coveralls.io/r/smileyborg/PureLayout) [![Version](http://img.shields.io/cocoapods/v/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![Platform](http://img.shields.io/cocoapods/p/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![License](http://img.shields.io/cocoapods/l/PureLayout.svg?style=flat)](LICENSE) [![Build Status](http://img.shields.io/travis/smileyborg/PureLayout.svg?style=flat)](https://travis-ci.org/smileyborg/PureLayout) [![Test Coverage](http://img.shields.io/coveralls/smileyborg/PureLayout.svg?style=flat)](https://coveralls.io/r/smileyborg/PureLayout) [![Version](http://img.shields.io/cocoapods/v/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![Platform](http://img.shields.io/cocoapods/p/PureLayout.svg?style=flat)](http://cocoapods.org/?q=PureLayout) [![License](http://img.shields.io/cocoapods/l/PureLayout.svg?style=flat)](LICENSE)
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. 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 a cross-platform Objective-C library that works (and looks!) great in Swift. It is fully backwards-compatible with all versions of iOS and OS X that support Auto Layout.
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. 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.
### Table of Contents
1. [Setup](#setup)
1. [API Cheat Sheet](#api-cheat-sheet)
1. [Usage](#usage)
* [Sample Code](#sample-code-swift)
* [Example Apps](#example-apps)
1. [PureLayout vs. the rest](#purelayout-vs-the-rest)
1. [Problems, Suggestions, Pull Requests?](#problems-suggestions-pull-requests)
## Setup
### Compatibility
The current release of PureLayout supports all versions of iOS and OS X since the introduction of Auto Layout on each platform, in both Swift and Objective-C, with a single codebase!
* Xcode
* Language Support: **Swift** *(any version)*, **Objective-C**
* Fully Compatible With: **Xcode 7.0**
* Minimum Supported Version: **Xcode 5.0**
* iOS
* Fully Compatible With: **iOS 9.0**
* Minimum Deployment Target: **iOS 6.0**
* OS X
* Fully Compatible With: **OS X 10.11**
* Minimum Deployment Target: **OS X 10.7**
### Using [CocoaPods](http://cocoapods.org)
1. Add the pod `PureLayout` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html).
```ruby
pod 'PureLayout'
```
1. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode.
1. Import the `PureLayout.h` umbrella header.
* With `use_frameworks!` in your Podfile
* Swift: `import PureLayout`
* Objective-C: `#import <PureLayout/PureLayout.h>` (or with Modules enabled: `@import PureLayout;`)
* Without `use_frameworks!` in your Podfile
* Swift: Add `#import "PureLayout.h"` to your bridging header.
* Objective-C: `#import "PureLayout.h"`
That's it - now go write some beautiful Auto Layout code!
### Using [Carthage](https://github.com/Carthage/Carthage)
1. Add the `smileyborg/PureLayout` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).
```ogdl
github "smileyborg/PureLayout"
```
1. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the framework into your project.
1. Import the PureLayout framework/module.
* Swift: `import PureLayout`
* Objective-C: `#import <PureLayout/PureLayout.h>` (or with Modules enabled: `@import PureLayout;`)
That's it - now go write some beautiful Auto Layout code!
### Manually from GitHub
1. Download the source files in the [PureLayout subdirectory](PureLayout/PureLayout).
1. Add the source files to your Xcode project.
1. Import the `PureLayout.h` header.
* Swift: Add `#import "PureLayout.h"` to your bridging header.
* Objective-C: `#import "PureLayout.h"`
That's it - now go write some beautiful Auto Layout code!
### App Extensions
To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. [Click here](https://github.com/smileyborg/PureLayout/wiki/App-Extensions) for more info.
### Releases
Releases are tagged in the git commit history using [semantic versioning](http://semver.org). Check out the [releases and release notes](https://github.com/smileyborg/PureLayout/releases) for each version.
## API Cheat Sheet ## API Cheat Sheet
This is just a handy overview of the core API methods. Explore the [header files](PureLayout/PureLayout) for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes: This is just a handy overview of the core API methods. Explore the [header files](PureLayout/PureLayout) for the full API, and find the complete documentation above the implementation of each method in the corresponding .m file. A couple of notes:
* All of the public API methods are namespaced with the prefix `auto...`, which also makes it easy for Xcode to autocomplete as you type. * All of the public API methods are namespaced with the prefix `auto...`, which also makes it easy for Xcode to autocomplete as you type.
* Methods that create constraints also automatically install (activate) the constraint(s), then return the new constraint(s) for you to optionally store for later adjustment or removal. * Methods that create constraints also automatically install (activate) the constraint(s), then return the new constraint(s) for you to optionally store for later adjustment or removal.
* Many methods below also have a variant which includes a `relation:` parameter to make the constraint an inequality. * Many methods below also have a variant which includes a `relation:` parameter to make the constraint an inequality.
### Attributes ### Attributes
@ -27,91 +98,88 @@ There are 5 specific attribute types, which are used throughout most of the API:
Additionally, 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!) Additionally, 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`](PureLayout/PureLayout/ALView%2BPureLayout.h) ### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h)
```
+ autoCreateConstraintsWithoutInstalling: - autoSetContent(CompressionResistance|Hugging)PriorityForAxis:
+ autoSetPriority:forConstraints: - autoCenterInSuperview(Margins): // Margins variant iOS 8.0+ only
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only - autoAlignAxisToSuperview(Margin)Axis: // Margin variant iOS 8.0+ only
- autoSetContent(CompressionResistance|Hugging)PriorityForAxis: - autoPinEdgeToSuperview(Edge:|Margin:)(withInset:) // Margin variant iOS 8.0+ only
- autoCenterInSuperview: - autoPinEdgesToSuperview(Edges|Margins)(WithInsets:)(excludingEdge:) // Margins variant iOS 8.0+ only
- autoAlignAxisToSuperviewAxis: - autoPinEdge:toEdge:ofView:(withOffset:)
- autoCenterInSuperviewMargins: // iOS 8.0+ only - autoAlignAxis:toSameAxisOfView:(withOffset:|withMultiplier:)
- autoAlignAxisToSuperviewMarginAxis: // iOS 8.0+ only - autoMatchDimension:toDimension:ofView:(withOffset:|withMultiplier:)
- autoPinEdgeToSuperviewEdge:(withInset:) - autoSetDimension(s)ToSize:
- autoPinEdgesToSuperviewEdgesWithInsets:(excludingEdge:) - autoConstrainAttribute:toAttribute:ofView:(withOffset:|withMultiplier:)
- autoPinEdgeToSuperviewMargin: // iOS 8.0+ only - autoPinTo(Top|Bottom)LayoutGuideOfViewController:withInset: // iOS 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`](PureLayout/PureLayout/NSArray%2BPureLayout.h) ### [`NSArray`](PureLayout/PureLayout/NSArray%2BPureLayout.h)
```
// Arrays of Constraints
- autoInstallConstraints
- autoRemoveConstraints
- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only
// Arrays of Constraints // Arrays of Views
- autoInstallConstraints - autoAlignViewsToEdge:
- autoRemoveConstraints - autoAlignViewsToAxis:
- autoIdentifyConstraints: // iOS 7.0+, OS X 10.9+ only - autoMatchViewsDimension:
- autoSetViewsDimension:toSize:
// Arrays of Views - autoSetViewsDimensionsToSize:
- autoAlignViewsToEdge: - autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:)
- autoAlignViewsToAxis: - autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:)
- autoMatchViewsDimension: ```
- autoSetViewsDimension:toSize:
- autoSetViewsDimensionsToSize:
- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:)
- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:)
### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h) ### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h)
```
- autoInstall + autoCreateAndInstallConstraints:
- autoRemove + autoCreateConstraintsWithoutInstalling:
- autoIdentify: // iOS 7.0+, OS X 10.9+ only + autoSetPriority:forConstraints:
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only
## Setup - 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* - autoInstall
- autoRemove
### Using [CocoaPods](http://cocoapods.org) ```
1. Add the pod `PureLayout` to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html).
pod 'PureLayout'
2. Run `pod install` from Terminal, then open your app's `.xcworkspace` file to launch Xcode.
3. 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!
### Using [Carthage](https://github.com/Carthage/Carthage)
1. Add the `smileyborg/PureLayout` project to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile).
github "smileyborg/PureLayout"
2. Run `carthage update`, then follow the [additional steps required](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application) to add the iOS and/or Mac frameworks into your project.
3. Import the PureLayout framework/module (with the appropriate name for the platform you're using it on).
* Using Modules: `@import PureLayout_iOS` or `@import PureLayout_Mac`
* Without Modules: `#import <PureLayout_iOS/PureLayout_iOS.h>` or `#import <PureLayout_Mac/PureLayout_Mac.h>`
That's it - now go write some beautiful Auto Layout code!
### Manually from GitHub
1. Download the source files in the [PureLayout subdirectory](PureLayout/PureLayout).
2. Add the source files to your Xcode project.
3. Import the `PureLayout.h` header.
That's it - now go write some beautiful Auto Layout code!
### App Extensions
To use PureLayout in an App Extension, you need to do a bit of extra configuration to prevent usage of unavailable APIs. [Click here](https://github.com/smileyborg/PureLayout/wiki/App-Extensions) for more info.
### Releases
Releases are tagged in the git commit history using [semantic versioning](http://semver.org). Check out the [releases and release notes](https://github.com/smileyborg/PureLayout/releases) for each version.
## Usage ## Usage
### Example Project ### Sample Code (Swift)
Open the project included in the repository (requires Xcode 6 or higher). It contains [iOS](PureLayout/Example-iOS) (`Example-iOS` scheme) and [OS X](PureLayout/Example-Mac) (`Example-Mac` scheme) demos of the library being used in various scenarios. PureLayout dramatically simplifies writing Auto Layout code. Let's take a quick look at some examples, using PureLayout from Swift.
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). Here's a constraint between two views created (and automatically activated) using PureLayout:
```swift
view1.autoPinEdge(.Top, toEdge: .Bottom, ofView: view2)
```
Without PureLayout, here's the equivalent code you'd have to write using Apple's Foundation API directly:
```swift
NSLayoutConstraint(item: view1, attribute: .Top, relatedBy: .Equal, toItem: view2, attribute: .Bottom, multiplier: 1.0, constant: 0.0).active = true
```
Many APIs of PureLayout create multiple constraints for you under the hood, letting you write highly readable layout code:
```swift
// 2 constraints created & activated in one line!
logoImageView.autoCenterInSuperview()
// 4 constraints created & activated in one line!
textContentView.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 20.0, left: 5.0, bottom: 10.0, right: 5.0))
```
PureLayout always returns the constraints it creates so you have full control:
```swift
let constraint = skinnyView.autoMatchDimension(.Height, toDimension: .Width, ofView: tallView)
```
PureLayout supports all Auto Layout features including inequalities, priorities, layout margins, identifiers, and much more. It's a comprehensive, developer-friendly way to use Auto Layout.
Check out the example apps below for many more demos of PureLayout in use.
### Example Apps
Open the project included in the repository (requires Xcode 6 or higher). It contains [iOS](PureLayout/Example-iOS) (`Example-iOS` scheme) and [OS X](PureLayout/Example-Mac) (`Example-Mac` scheme) demos of the library being used in various scenarios. The demos in the iOS example app make a great introductory tutorial to PureLayout -- run each demo, review the code used to implement it, then practice by making some changes of your own to the demo code.
Each demo in the iOS example app has a Swift and Objective-C version. **To compile & run the Swift demos, you must use Xcode 7.0 or higher (Swift 2.0) and choose the `Example-iOS-Xcode7` scheme.** When you run the example app, you can easily switch between using the Swift and Objective-C versions of the demos. To see the constraints in action while running the iOS demos, try using different device simulators, rotating the device to different orientations, as well as toggling 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. 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.
@ -119,30 +187,33 @@ On OS X, while running the app, press any key to cycle through the demos. You ca
Check out some [Tips and Tricks](https://github.com/smileyborg/PureLayout/wiki/Tips-and-Tricks) to keep in mind when using the API. Check out some [Tips and Tricks](https://github.com/smileyborg/PureLayout/wiki/Tips-and-Tricks) to keep in mind when using the API.
## PureLayout vs. the rest ## PureLayout vs. the rest
An overview of the Auto Layout options available, ordered from the lowest- to highest-level of abstraction. There are quite a few different ways to implement Auto Layout. Here is a quick overview of the available options:
* Apple [NSLayoutConstraint SDK API](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:) * Apple [NSLayoutConstraint SDK API](https://developer.apple.com/library/ios/documentation/AppKit/Reference/NSLayoutConstraint_Class/index.html#//apple_ref/occ/clm/NSLayoutConstraint/constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:)
* Pros: Raw power * Pros: Raw power
* Cons: Extremely verbose, tedious to write, difficult to read * Cons: Extremely verbose; tedious to write; difficult to read
* Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html) * Apple [Visual Format Language](https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/VisualFormatLanguage/VisualFormatLanguage.html)
* Pros: Concise, convenient * Pros: Concise; convenient
* Cons: Doesn't support some use cases, incomplete compile-time checks, must learn syntax, hard to debug * Cons: Doesn't support some use cases; lacks compile-time checking and safety; must learn syntax; hard to debug
* Apple Interface Builder * Apple Interface Builder
* Pros: Visual, simple * Pros: Visual; interactive; provides compile-time layout checking
* Cons: Difficult for complex layouts, cannot dynamically set constraints at runtime, encourages hardcoded magic numbers, not always WYSIWYG * Cons: Difficult for complex layouts; cannot dynamically set constraints at runtime; encourages hardcoded magic numbers; not always WYSIWYG
* **PureLayout** * Apple [NSLayoutAnchor SDK API](https://developer.apple.com/library/prerelease/ios/documentation/AppKit/Reference/NSLayoutAnchor_ClassReference/index.html)
* Pros: Simple, efficient, minimal third party code, consistent with Cocoa API style, compatible with Objective-C and Swift codebases * Pros: Clean, readable, and type-safe API for creating individual constraints
* Cons: Not the most concise expression of layout code * Cons: Only available in iOS 9.0 and OS X 10.11 and higher; requires manually activating each constraint; no API for creating multiple constraints at once
* High-level Auto Layout Libraries/DSLs ([Cartography](https://github.com/robb/Cartography), [SnapKit](https://github.com/SnapKit/SnapKit), [KeepLayout](https://github.com/iMartinKiss/KeepLayout)) * **PureLayout**
* Pros: Very clean, concise, and convenient * Pros: Compatible with Objective-C and Swift codebases; consistent with Cocoa API style; cross-platform API and implementation shared across iOS and OS X; fully backwards-compatible to iOS 6 & OS X 10.7; easy to use; type-safe; efficient
* Cons: Unique API style is foreign to Cocoa APIs, mixed compatibility with Objective-C & Swift, greater dependency on third party code * Cons: Not the most concise expression of layout code
* High-level Auto Layout Libraries/DSLs ([Cartography](https://github.com/robb/Cartography), [SnapKit](https://github.com/SnapKit/SnapKit), [KeepLayout](https://github.com/iMartinKiss/KeepLayout))
* Pros: Very clean, concise, and convenient
* Cons: Unique API style is foreign to Apple's APIs; mixed compatibility with Objective-C & Swift; greater dependency on third party code
PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project. PureLayout takes a balanced approach to Auto Layout that makes it well suited for any project.
## Problems, Suggestions, Pull Requests? ## Problems, Suggestions, Pull Requests?
Please open a [new Issue here](https://github.com/smileyborg/PureLayout/issues/new) 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](http://stackoverflow.com). Please open a [new Issue here](https://github.com/smileyborg/PureLayout/issues/new) if you run into a problem specific to PureLayout, have a feature request, or want to share a comment. Note that general Auto Layout questions should be asked on [Stack Overflow](http://stackoverflow.com).
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. Pull requests are encouraged and greatly appreciated! Please try to maintain consistency with the existing code style. 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.
## Meta ## Meta
Designed & maintained by Tyler Fox ([@smileyborg](https://twitter.com/smileyborg)). Distributed with the MIT license. Designed & maintained by Tyler Fox ([@smileyborg](https://twitter.com/smileyborg)). Distributed with the MIT license.

View File

@ -1,9 +0,0 @@
#include "Pods-PureLayout.xcconfig"
CONFIGURATION_BUILD_DIR = $PODS_FRAMEWORK_BUILD_PATH
FRAMEWORK_SEARCH_PATHS = "$PODS_FRAMEWORK_BUILD_PATH"
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Private/PureLayout" "${PODS_ROOT}/Headers/Public" "${PODS_ROOT}/Headers/Public/PureLayout" "${PODS_ROOT}/Headers/Public/TabBarPicker" "${PODS_ROOT}/Headers/Public/pop"
OTHER_LDFLAGS = -ObjC
PODS_FRAMEWORK_BUILD_PATH = $(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/Pods
PODS_ROOT = ${SRCROOT}
SKIP_INSTALL = YES

View File

@ -1,5 +0,0 @@
#import <Foundation/Foundation.h>
@interface PodsDummy_Pods_PureLayout : NSObject
@end
@implementation PodsDummy_Pods_PureLayout
@end

Some files were not shown because too many files have changed in this diff Show More