no message
This commit is contained in:
parent
6c0f2bbae5
commit
4d7c6109a6
@ -1,6 +1,6 @@
|
||||
PODS:
|
||||
- pop (1.0.7)
|
||||
- PureLayout (2.0.6)
|
||||
- PureLayout (3.0.0)
|
||||
- TabBarPicker (0.1.0)
|
||||
- UIView-Overlay (0.1)
|
||||
|
||||
@ -16,7 +16,7 @@ EXTERNAL SOURCES:
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
pop: 628ffc631644601567ee8bfaaaea493ebd7d0923
|
||||
PureLayout: f25f0bb904d5ccfe6e31da3cb869185259f02e0d
|
||||
PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d
|
||||
TabBarPicker: 0b8b0c04ad47ed9c740cef5d31cac7fefe6cb273
|
||||
UIView-Overlay: 95e42e733f6fdcfca523a399ba7907d0ca4570a0
|
||||
|
||||
|
||||
1
Example/Pods/Headers/Private/TabBarPicker/SharedLocationManager.h
generated
Symbolic link
1
Example/Pods/Headers/Private/TabBarPicker/SharedLocationManager.h
generated
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../../Pod/Classes/Vendor/SharedLocationManager/SharedLocationManager.h
|
||||
1
Example/Pods/Headers/Private/TabBarPicker/UIButton+BackgroundColor.h
generated
Symbolic link
1
Example/Pods/Headers/Private/TabBarPicker/UIButton+BackgroundColor.h
generated
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../../Pod/Classes/Vendor/UIButton+BackgroundColor/UIButton+BackgroundColor.h
|
||||
1
Example/Pods/Headers/Private/TabBarPicker/UIImage+Color.h
generated
Symbolic link
1
Example/Pods/Headers/Private/TabBarPicker/UIImage+Color.h
generated
Symbolic link
@ -0,0 +1 @@
|
||||
../../../../../Pod/Classes/Vendor/UIButton+BackgroundColor/UIImage+Color.h
|
||||
4
Example/Pods/Manifest.lock
generated
4
Example/Pods/Manifest.lock
generated
@ -1,6 +1,6 @@
|
||||
PODS:
|
||||
- pop (1.0.7)
|
||||
- PureLayout (2.0.6)
|
||||
- PureLayout (3.0.0)
|
||||
- TabBarPicker (0.1.0)
|
||||
- UIView-Overlay (0.1)
|
||||
|
||||
@ -16,7 +16,7 @@ EXTERNAL SOURCES:
|
||||
|
||||
SPEC CHECKSUMS:
|
||||
pop: 628ffc631644601567ee8bfaaaea493ebd7d0923
|
||||
PureLayout: f25f0bb904d5ccfe6e31da3cb869185259f02e0d
|
||||
PureLayout: 270dfee2236f697ab1d5e2771c2e5c248495fa0d
|
||||
TabBarPicker: 0b8b0c04ad47ed9c740cef5d31cac7fefe6cb273
|
||||
UIView-Overlay: 95e42e733f6fdcfca523a399ba7907d0ca4570a0
|
||||
|
||||
|
||||
614
Example/Pods/Pods.xcodeproj/project.pbxproj
generated
614
Example/Pods/Pods.xcodeproj/project.pbxproj
generated
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "27DE53AEDDAB00F74933876B"
|
||||
BlueprintIdentifier = "CBB966AFD951D7E5D5A60409"
|
||||
BuildableName = "TabBarPicker.framework"
|
||||
BlueprintName = "TabBarPicker"
|
||||
ReferencedContainer = "container:Pods.xcodeproj">
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// ALView+PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
@ -30,7 +29,9 @@
|
||||
#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.
|
||||
@ -46,36 +47,14 @@
|
||||
/** Initializes and returns a new view that does not convert the autoresizing mask into constraints. */
|
||||
- (instancetype)initForAutoLayout;
|
||||
|
||||
|
||||
#pragma mark Create Constraints Without Installing
|
||||
|
||||
/** 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 */
|
||||
/** Configures an existing view to not convert the autoresizing mask into constraints and returns the view. */
|
||||
- (instancetype)configureForAutoLayout;
|
||||
|
||||
|
||||
#pragma mark Center & Align in Superview
|
||||
|
||||
/** Centers the view in its superview. */
|
||||
- (NSArray *)autoCenterInSuperview;
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoCenterInSuperview;
|
||||
|
||||
/** Aligns the view to the same axis of its superview. */
|
||||
- (NSLayoutConstraint *)autoAlignAxisToSuperviewAxis:(ALAxis)axis;
|
||||
@ -83,7 +62,7 @@
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
/** 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. */
|
||||
- (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. */
|
||||
- (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. */
|
||||
- (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. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewEdgesWithInsets:(ALEdgeInsets)insets excludingEdge:(ALEdge)edge;
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0
|
||||
|
||||
@ -117,10 +99,10 @@
|
||||
- (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. */
|
||||
- (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. */
|
||||
- (NSArray *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoPinEdgesToSuperviewMarginsExcludingEdge:(ALEdge)edge;
|
||||
|
||||
#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. */
|
||||
- (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
|
||||
|
||||
@ -167,7 +152,7 @@
|
||||
#pragma mark Set Dimensions
|
||||
|
||||
/** 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. */
|
||||
- (NSLayoutConstraint *)autoSetDimension:(ALDimension)dimension toSize:(CGFloat)size;
|
||||
@ -179,11 +164,11 @@
|
||||
#pragma mark Set Content Compression Resistance & Hugging
|
||||
|
||||
/** 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;
|
||||
|
||||
/** 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;
|
||||
|
||||
|
||||
@ -223,31 +208,6 @@
|
||||
|
||||
#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
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// ALView+PureLayout.m
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
@ -62,198 +61,14 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Create Constraints Without Installing
|
||||
|
||||
/**
|
||||
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).
|
||||
Configures an existing view to not convert the autoresizing mask into constraints and returns the view.
|
||||
*/
|
||||
static NSMutableArray *_al_arraysOfCreatedConstraints = nil;
|
||||
|
||||
/**
|
||||
Accessor for the global state that stores arrays of constraints created without being installed.
|
||||
*/
|
||||
+ (NSMutableArray *)al_arraysOfCreatedConstraints
|
||||
- (instancetype)configureForAutoLayout
|
||||
{
|
||||
if (!_al_arraysOfCreatedConstraints) {
|
||||
_al_arraysOfCreatedConstraints = [NSMutableArray new];
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
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
|
||||
@ -263,9 +78,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
|
||||
@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:ALAxisVertical]];
|
||||
return constraints;
|
||||
@ -292,9 +107,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
|
||||
@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:ALAxisVertical]];
|
||||
return constraints;
|
||||
@ -368,6 +183,16 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
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.
|
||||
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.
|
||||
@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:ALEdgeLeading withInset:insets.left]];
|
||||
[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.
|
||||
@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) {
|
||||
[constraints addObject:[self autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:insets.top]];
|
||||
}
|
||||
@ -454,9 +279,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
|
||||
@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:ALEdgeLeading]];
|
||||
[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.
|
||||
@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) {
|
||||
[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];
|
||||
}
|
||||
|
||||
/**
|
||||
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
|
||||
|
||||
@ -646,9 +484,9 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
@param size The size to set this view's dimensions to.
|
||||
@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:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
@ -694,14 +532,14 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
- (void)autoSetContentCompressionResistancePriorityForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
|
||||
if ([ALView al_isExecutingPriorityConstraintsBlock]) {
|
||||
NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
|
||||
#if TARGET_OS_IPHONE
|
||||
[self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis];
|
||||
[self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
|
||||
#else
|
||||
[self setContentCompressionResistancePriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
|
||||
[self setContentCompressionResistancePriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
}
|
||||
}
|
||||
@ -714,14 +552,14 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
*/
|
||||
- (void)autoSetContentHuggingPriorityForAxis:(ALAxis)axis
|
||||
{
|
||||
NSAssert([ALView al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
|
||||
if ([ALView al_isExecutingPriorityConstraintsBlock]) {
|
||||
NSAssert([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock], @"%@ should only be called from within the block passed into the method +[autoSetPriority:forConstraints:]", NSStringFromSelector(_cmd));
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
self.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
ALLayoutConstraintAxis constraintAxis = [NSLayoutConstraint al_constraintAxisForAxis:axis];
|
||||
#if TARGET_OS_IPHONE
|
||||
[self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forAxis:constraintAxis];
|
||||
[self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forAxis:constraintAxis];
|
||||
#else
|
||||
[self setContentHuggingPriority:[ALView al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
|
||||
[self setContentHuggingPriority:[NSLayoutConstraint al_currentGlobalConstraintPriority] forOrientation:constraintAxis];
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
}
|
||||
}
|
||||
@ -884,100 +722,8 @@ static NSMutableArray *_al_globalConstraintIdentifiers = nil;
|
||||
#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
|
||||
|
||||
/**
|
||||
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.
|
||||
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
|
||||
{
|
||||
[ALView al_applyGlobalStateToConstraint:constraint];
|
||||
if ([ALView al_preventAutomaticConstraintInstallation]) {
|
||||
[[ALView al_currentArrayOfCreatedConstraints] addObject:constraint];
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:constraint];
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
[[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:constraint];
|
||||
} else {
|
||||
[self addConstraint:constraint];
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// NSArray+PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
@ -30,7 +29,9 @@
|
||||
#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:
|
||||
@ -48,60 +49,67 @@
|
||||
/** Deactivates the constraints in this array. */
|
||||
- (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. */
|
||||
- (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
|
||||
|
||||
/** 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. */
|
||||
- (NSArray *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoAlignViewsToAxis:(ALAxis)axis;
|
||||
|
||||
/** 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. */
|
||||
- (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. */
|
||||
- (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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
/** 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. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
/** 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. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
/** 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. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
/** 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. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
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. */
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
/** 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. */
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
insetSpacing:(BOOL)shouldSpaceInsets;
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// NSArray+PureLayout.m
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2012 Richard Turton
|
||||
@ -49,11 +48,11 @@
|
||||
if ([NSLayoutConstraint respondsToSelector:@selector(activateConstraints:)]) {
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[NSLayoutConstraint class]]) {
|
||||
[ALView al_applyGlobalStateToConstraint:object];
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:object];
|
||||
}
|
||||
}
|
||||
if ([ALView al_preventAutomaticConstraintInstallation]) {
|
||||
[[ALView al_currentArrayOfCreatedConstraints] addObjectsFromArray:self];
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
[[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObjectsFromArray:self];
|
||||
} else {
|
||||
[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.
|
||||
@ -107,7 +106,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Array of Views
|
||||
@ -119,10 +118,10 @@
|
||||
@param edge The edge to which the views will be aligned.
|
||||
@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.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@ -144,10 +143,10 @@
|
||||
@param axis The axis to which the views will be aligned.
|
||||
@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.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@ -169,10 +168,10 @@
|
||||
@param dimension The dimension to match for all of the views.
|
||||
@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.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@ -195,10 +194,10 @@
|
||||
@param size The size to set the given dimension of each view to.
|
||||
@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.");
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
ALView *view = (ALView *)object;
|
||||
@ -216,9 +215,9 @@
|
||||
@param size The size to set each view's dimensions to.
|
||||
@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:ALDimensionHeight toSize:size.height]];
|
||||
return constraints;
|
||||
@ -235,7 +234,7 @@
|
||||
@param spacing The fixed amount of spacing between each view.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
{
|
||||
@ -256,7 +255,7 @@
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
@ -281,13 +280,13 @@
|
||||
NOTE: All views must specify an intrinsic content size if passing NO, otherwise the layout will be ambiguous!
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSpacing:(CGFloat)spacing
|
||||
insetSpacing:(BOOL)shouldSpaceInsets
|
||||
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;
|
||||
ALEdge firstEdge, lastEdge;
|
||||
switch (axis) {
|
||||
@ -312,7 +311,7 @@
|
||||
CGFloat leadingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
CGFloat trailingSpacing = shouldSpaceInsets ? spacing : 0.0;
|
||||
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
ALView *previousView = nil;
|
||||
for (id object in self) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
@ -350,7 +349,7 @@
|
||||
@param size The fixed size of each view in the dimension along the given axis.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
{
|
||||
@ -371,12 +370,12 @@
|
||||
@param shouldSpaceInsets Whether the first and last views should be equally inset from their superview.
|
||||
@return An array of constraints added.
|
||||
*/
|
||||
- (NSArray *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
- (__NSArray_of(NSLayoutConstraint *) *)autoDistributeViewsAlongAxis:(ALAxis)axis
|
||||
alignedTo:(ALAttribute)alignment
|
||||
withFixedSize:(CGFloat)size
|
||||
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;
|
||||
NSLayoutAttribute attribute;
|
||||
switch (axis) {
|
||||
@ -408,8 +407,8 @@
|
||||
#endif /* TARGET_OS_IPHONE */
|
||||
BOOL shouldFlipOrder = isRightToLeftLayout && (axis != ALAxisVertical); // imitate the effect of leading/trailing when distributing horizontally
|
||||
|
||||
NSMutableArray *constraints = [NSMutableArray new];
|
||||
NSArray *views = [self al_copyViewsOnly];
|
||||
__NSMutableArray_of(NSLayoutConstraint *) *constraints = [NSMutableArray new];
|
||||
__NSArray_of(ALView *) *views = [self al_copyViewsOnly];
|
||||
NSUInteger numberOfViews = [views count];
|
||||
ALView *commonSuperview = [views al_commonSuperviewOfViews];
|
||||
ALView *previousView = nil;
|
||||
@ -443,7 +442,7 @@
|
||||
#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.
|
||||
|
||||
@return The common superview for the views in this array.
|
||||
@ -458,7 +457,7 @@
|
||||
if (previousView) {
|
||||
commonSuperview = [view al_commonSuperviewWithView:commonSuperview];
|
||||
} else {
|
||||
commonSuperview = view;
|
||||
commonSuperview = view.superview;
|
||||
}
|
||||
previousView = view;
|
||||
}
|
||||
@ -492,9 +491,9 @@
|
||||
|
||||
@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) {
|
||||
if ([object isKindOfClass:[ALView class]]) {
|
||||
[viewsOnlyArray addObject:object];
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// NSLayoutConstraint+PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
@ -29,7 +28,9 @@
|
||||
#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.
|
||||
@ -37,6 +38,39 @@
|
||||
@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
|
||||
|
||||
/** Activates the the constraint. */
|
||||
@ -45,14 +79,6 @@
|
||||
/** Deactivates the constraint. */
|
||||
- (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
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// NSLayoutConstraint+PureLayout.m
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2013-2015 Tyler Fox
|
||||
@ -28,6 +27,7 @@
|
||||
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
#import "ALView+PureLayout.h"
|
||||
#import "NSArray+PureLayout.h"
|
||||
#import "PureLayout+Internal.h"
|
||||
|
||||
|
||||
@ -35,8 +35,250 @@
|
||||
|
||||
@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.
|
||||
@ -45,9 +287,9 @@
|
||||
{
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
if ([self respondsToSelector:@selector(setActive:)]) {
|
||||
[ALView al_applyGlobalStateToConstraint:self];
|
||||
if ([ALView al_preventAutomaticConstraintInstallation]) {
|
||||
[[ALView al_currentArrayOfCreatedConstraints] addObject:self];
|
||||
[NSLayoutConstraint al_applyGlobalStateToConstraint:self];
|
||||
if ([NSLayoutConstraint al_preventAutomaticConstraintInstallation]) {
|
||||
[[NSLayoutConstraint al_currentArrayOfCreatedConstraints] addObject:self];
|
||||
} else {
|
||||
self.active = YES;
|
||||
}
|
||||
@ -101,30 +343,26 @@
|
||||
}
|
||||
|
||||
|
||||
#pragma mark Identify Constraints
|
||||
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
#pragma mark Internal Methods
|
||||
|
||||
/**
|
||||
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.
|
||||
Applies the global constraint priority and identifier to the given constraint.
|
||||
This should be done before installing all constraints.
|
||||
|
||||
@param identifier A string used to identify this constraint.
|
||||
@return This constraint.
|
||||
@param constraint The constraint to set the global priority and identifier on.
|
||||
*/
|
||||
- (instancetype)autoIdentify:(NSString *)identifier
|
||||
+ (void)al_applyGlobalStateToConstraint:(NSLayoutConstraint *)constraint
|
||||
{
|
||||
if ([self respondsToSelector:@selector(setIdentifier:)]) {
|
||||
self.identifier = identifier;
|
||||
if ([NSLayoutConstraint al_isExecutingPriorityConstraintsBlock]) {
|
||||
constraint.priority = [NSLayoutConstraint al_currentGlobalConstraintPriority];
|
||||
}
|
||||
return self;
|
||||
#if __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10
|
||||
NSString *globalConstraintIdentifier = [NSLayoutConstraint al_currentGlobalConstraintIdentifier];
|
||||
if (globalConstraintIdentifier) {
|
||||
[constraint autoIdentify:globalConstraintIdentifier];
|
||||
}
|
||||
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 || __PureLayout_MinBaseSDK_OSX_10_10 */
|
||||
|
||||
|
||||
#pragma mark Internal Methods
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the corresponding NSLayoutAttribute for the given ALAttribute.
|
||||
@ -234,7 +472,7 @@
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
return constraintAxis;
|
||||
@ -273,7 +511,7 @@
|
||||
break;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
return margin;
|
||||
@ -299,11 +537,11 @@
|
||||
case ALAxisBaseline:
|
||||
case ALAxisFirstBaseline:
|
||||
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;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
return marginAxis;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// PureLayout+Internal.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
@ -28,9 +27,15 @@
|
||||
|
||||
#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,
|
||||
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)
|
||||
|
||||
+ (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;
|
||||
- (ALView *)al_commonSuperviewWithView:(ALView *)otherView;
|
||||
- (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;
|
||||
- (BOOL)al_containsMinimumNumberOfViews:(NSUInteger)minimumNumberOfViews;
|
||||
- (NSArray *)al_copyViewsOnly;
|
||||
- (__NSArray_of(ALView *) *)al_copyViewsOnly;
|
||||
|
||||
@end
|
||||
|
||||
@ -68,6 +67,14 @@ static const CGFloat kMULTIPLIER_MIN_VALUE = 0.00001; // very small floating poi
|
||||
*/
|
||||
@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;
|
||||
+ (ALLayoutConstraintAxis)al_constraintAxisForAxis:(ALAxis)axis;
|
||||
#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 */
|
||||
|
||||
@end
|
||||
|
||||
__PL_ASSUME_NONNULL_END
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// PureLayout.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// Copyright (c) 2014-2015 Tyler Fox
|
||||
@ -29,6 +28,14 @@
|
||||
#ifndef 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 "NSArray+PureLayout.h"
|
||||
#import "NSLayoutConstraint+PureLayout.h"
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//
|
||||
// PureLayoutDefines.h
|
||||
// v2.0.5
|
||||
// https://github.com/smileyborg/PureLayout
|
||||
//
|
||||
// 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_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
|
||||
# import <UIKit/UIKit.h>
|
||||
# define ALView UIView
|
||||
@ -108,9 +126,9 @@ typedef NS_ENUM(NSInteger, ALDimension) {
|
||||
|
||||
/** Constants that represent axes of a view. */
|
||||
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,
|
||||
/** 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,
|
||||
|
||||
/** 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. */
|
||||
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,
|
||||
/** 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
|
||||
};
|
||||
|
||||
@ -170,9 +188,9 @@ typedef NS_ENUM(NSInteger, ALAttribute) {
|
||||
ALAttributeWidth = ALDimensionWidth,
|
||||
/** The height of the view. */
|
||||
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,
|
||||
/** 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,
|
||||
/** 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,
|
||||
@ -193,9 +211,9 @@ typedef NS_ENUM(NSInteger, ALAttribute) {
|
||||
ALAttributeMarginLeading = ALMarginLeading,
|
||||
/** The trailing margin of the view, based on the view's layoutMargins left/right (depending on language direction) inset. */
|
||||
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,
|
||||
/** 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
|
||||
#endif /* __PureLayout_MinBaseSDK_iOS_8_0 */
|
||||
};
|
||||
|
||||
207
Example/Pods/PureLayout/README.md
generated
207
Example/Pods/PureLayout/README.md
generated
@ -1,10 +1,81 @@
|
||||
# [](#)
|
||||
[](https://travis-ci.org/smileyborg/PureLayout) [](https://coveralls.io/r/smileyborg/PureLayout) [](http://cocoapods.org/?q=PureLayout) [](http://cocoapods.org/?q=PureLayout) [](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.
|
||||
|
||||
### 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
|
||||
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:
|
||||
|
||||
@ -27,28 +98,22 @@ 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!)
|
||||
|
||||
### [`UIView`/`NSView`](PureLayout/PureLayout/ALView%2BPureLayout.h)
|
||||
|
||||
+ autoCreateConstraintsWithoutInstalling:
|
||||
+ autoSetPriority:forConstraints:
|
||||
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only
|
||||
```
|
||||
- autoSetContent(CompressionResistance|Hugging)PriorityForAxis:
|
||||
- autoCenterInSuperview:
|
||||
- autoAlignAxisToSuperviewAxis:
|
||||
- autoCenterInSuperviewMargins: // iOS 8.0+ only
|
||||
- autoAlignAxisToSuperviewMarginAxis: // iOS 8.0+ only
|
||||
- autoPinEdgeToSuperviewEdge:(withInset:)
|
||||
- autoPinEdgesToSuperviewEdgesWithInsets:(excludingEdge:)
|
||||
- autoPinEdgeToSuperviewMargin: // iOS 8.0+ only
|
||||
- autoPinEdgesToSuperviewMargins(ExcludingEdge:) // iOS 8.0+ only
|
||||
- autoCenterInSuperview(Margins): // Margins variant iOS 8.0+ only
|
||||
- autoAlignAxisToSuperview(Margin)Axis: // Margin variant iOS 8.0+ only
|
||||
- autoPinEdgeToSuperview(Edge:|Margin:)(withInset:) // Margin variant iOS 8.0+ only
|
||||
- autoPinEdgesToSuperview(Edges|Margins)(WithInsets:)(excludingEdge:) // Margins variant iOS 8.0+ only
|
||||
- autoPinEdge:toEdge:ofView:(withOffset:)
|
||||
- autoAlignAxis:toSameAxisOfView:(withOffset:)
|
||||
- autoAlignAxis:toSameAxisOfView:(withOffset:|withMultiplier:)
|
||||
- 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)
|
||||
|
||||
```
|
||||
// Arrays of Constraints
|
||||
- autoInstallConstraints
|
||||
- autoRemoveConstraints
|
||||
@ -62,56 +127,59 @@ Additionally, there is one generic attribute type, `ALAttribute`, which is effec
|
||||
- autoSetViewsDimensionsToSize:
|
||||
- autoDistributeViewsAlongAxis:alignedTo:withFixedSpacing:(insetSpacing:)(matchedSizes:)
|
||||
- autoDistributeViewsAlongAxis:alignedTo:withFixedSize:(insetSpacing:)
|
||||
```
|
||||
|
||||
### [`NSLayoutConstraint`](PureLayout/PureLayout/NSLayoutConstraint%2BPureLayout.h)
|
||||
|
||||
```
|
||||
+ autoCreateAndInstallConstraints:
|
||||
+ autoCreateConstraintsWithoutInstalling:
|
||||
+ autoSetPriority:forConstraints:
|
||||
+ autoSetIdentifier:forConstraints: // iOS 7.0+, OS X 10.9+ only
|
||||
- autoIdentify: // iOS 7.0+, OS X 10.9+ only
|
||||
- autoInstall
|
||||
- autoRemove
|
||||
- autoIdentify: // iOS 7.0+, OS X 10.9+ only
|
||||
|
||||
## Setup
|
||||
*Note: PureLayout requires a minimum deployment target of iOS 6.0 or 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).
|
||||
|
||||
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
|
||||
### Example Project
|
||||
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.
|
||||
### Sample Code (Swift)
|
||||
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.
|
||||
|
||||
@ -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.
|
||||
|
||||
## 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:)
|
||||
* 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)
|
||||
* Pros: Concise, convenient
|
||||
* Cons: Doesn't support some use cases, incomplete compile-time checks, must learn syntax, hard to debug
|
||||
* Pros: Concise; convenient
|
||||
* Cons: Doesn't support some use cases; lacks compile-time checking and safety; must learn syntax; hard to debug
|
||||
* Apple Interface Builder
|
||||
* Pros: Visual, simple
|
||||
* Cons: Difficult for complex layouts, cannot dynamically set constraints at runtime, encourages hardcoded magic numbers, not always WYSIWYG
|
||||
* 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
|
||||
* Apple [NSLayoutAnchor SDK API](https://developer.apple.com/library/prerelease/ios/documentation/AppKit/Reference/NSLayoutAnchor_ClassReference/index.html)
|
||||
* Pros: Clean, readable, and type-safe API for creating individual constraints
|
||||
* 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
|
||||
* **PureLayout**
|
||||
* Pros: Simple, efficient, minimal third party code, consistent with Cocoa API style, compatible with Objective-C and Swift codebases
|
||||
* 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: 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 Cocoa APIs, mixed compatibility with Objective-C & Swift, greater dependency on third party code
|
||||
* 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.
|
||||
|
||||
## 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
|
||||
Designed & maintained by Tyler Fox ([@smileyborg](https://twitter.com/smileyborg)). Distributed with the MIT license.
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.0.6</string>
|
||||
<string>3.0.0</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
|
||||
@ -6,6 +6,9 @@
|
||||
#import "TabBarSubItem.h"
|
||||
#import "MMCPSScrollView.h"
|
||||
#import "NSString+HexColor.h"
|
||||
#import "SharedLocationManager.h"
|
||||
#import "UIButton+BackgroundColor.h"
|
||||
#import "UIImage+Color.h"
|
||||
|
||||
FOUNDATION_EXPORT double TabBarPickerVersionNumber;
|
||||
FOUNDATION_EXPORT const unsigned char TabBarPickerVersionString[];
|
||||
|
||||
@ -24,40 +24,49 @@
|
||||
|
||||
if (self) {
|
||||
|
||||
TabBarSubItem *subItem1 = [TabBarSubItem tabBarSubItemWithName:@"Peppe"];
|
||||
TabBarSubItem *subItem2 = [TabBarSubItem tabBarSubItemWithName:@"Peppe1"];
|
||||
TabBarSubItem *subItem3 = [TabBarSubItem tabBarSubItemWithName:@"Peppe2"];
|
||||
TabBarSubItem *subItem4 = [TabBarSubItem tabBarSubItemWithName:@"Peppe3"];
|
||||
TabBarSubItem *subItem5 = [TabBarSubItem tabBarSubItemWithName:@"Peppe4"];
|
||||
TabBarSubItem *subItem6 = [TabBarSubItem tabBarSubItemWithName:@"Peppe5"];
|
||||
TabBarSubItem *subItem7 = [TabBarSubItem tabBarSubItemWithName:@"Peppe6"];
|
||||
TabBarSubItem *subItem1 = [TabBarSubItem tabBarSubItemWithName:@"Peppe" andValue:@"Peppe"];
|
||||
TabBarSubItem *subItem2 = [TabBarSubItem tabBarSubItemWithName:@"Peppe1" andValue:@"Peppe1"];
|
||||
TabBarSubItem *subItem3 = [TabBarSubItem tabBarSubItemWithName:@"Peppe2" andValue:@"Peppe2"];
|
||||
TabBarSubItem *subItem4 = [TabBarSubItem tabBarSubItemWithName:@"Peppe3" andValue:@"Peppe3"];
|
||||
TabBarSubItem *subItem5 = [TabBarSubItem tabBarSubItemWithName:@"Peppe4" andValue:@"Peppe4"];
|
||||
TabBarSubItem *subItem6 = [TabBarSubItem tabBarSubItemWithName:@"Peppe5" andValue:@"Peppe5"];
|
||||
TabBarSubItem *subItem7 = [TabBarSubItem tabBarSubItemWithName:@"Peppe6" andValue:@"Peppe6"];
|
||||
|
||||
TabBarPickerSubItemsView *locationSubview = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7] needsLocalization:YES];
|
||||
|
||||
TabBarItem *location = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
TabBarItem *location = [[TabBarItem alloc] initWithSubItemView:locationSubview];
|
||||
[location setItemName:@"Location"];
|
||||
[location setImage:[UIImage imageNamed:@"location"]];
|
||||
[location setSelectedImage:[UIImage imageNamed:@"location_selected"]];
|
||||
[location setHighlightedImage:[UIImage imageNamed:@"location_highlighted"]];
|
||||
|
||||
TabBarItem *calendar = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
TabBarPickerSubItemsView *calendarSubView = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
|
||||
TabBarItem *calendar = [[TabBarItem alloc] initWithSubItemView:calendarSubView];
|
||||
[calendar setItemName:@"Calendar"];
|
||||
[calendar setImage:[UIImage imageNamed:@"calendar"]];
|
||||
[calendar setSelectedImage:[UIImage imageNamed:@"calendar_selected"]];
|
||||
[calendar setHighlightedImage:[UIImage imageNamed:@"calendar_highlighted"]];
|
||||
|
||||
TabBarItem *type = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
TabBarPickerSubItemsView *typeSubView = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
|
||||
TabBarItem *type = [[TabBarItem alloc] initWithSubItemView:typeSubView];
|
||||
[type setItemName:@"Type"];
|
||||
[type setImage:[UIImage imageNamed:@"type"]];
|
||||
[type setSelectedImage:[UIImage imageNamed:@"type_selected"]];
|
||||
[type setHighlightedImage:[UIImage imageNamed:@"type_highlighted"]];
|
||||
|
||||
TabBarItem *price = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
TabBarPickerSubItemsView *priceSubView = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
|
||||
TabBarItem *price =[[TabBarItem alloc] initWithSubItemView:priceSubView];
|
||||
[price setItemName:@"Price"];
|
||||
[price setImage:[UIImage imageNamed:@"price"]];
|
||||
[price setSelectedImage:[UIImage imageNamed:@"price_selected"]];
|
||||
[price setHighlightedImage:[UIImage imageNamed:@"price_highlighted"]];
|
||||
|
||||
TabBarItem *allergen = [[TabBarItem alloc] initWithSubItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
TabBarPickerSubItemsView *allergenSubView = [[TabBarPickerSubItemsView alloc] initWithType:TabBarPickerSubItemsViewTypeButtons subItems:@[subItem1,subItem2,subItem3,subItem4,subItem5,subItem6,subItem7]];
|
||||
|
||||
TabBarItem *allergen = [[TabBarItem alloc] initWithSubItemView:allergenSubView];
|
||||
[allergen setItemName:@"Allergen"];
|
||||
[allergen setImage:[UIImage imageNamed:@"allergen"]];
|
||||
[allergen setSelectedImage:[UIImage imageNamed:@"allergen_selected"]];
|
||||
@ -100,7 +109,7 @@
|
||||
|
||||
- (void) viewDidAppear:(BOOL)animated {
|
||||
|
||||
[tabbar selectItem:0];
|
||||
//[tabbar selectItem:0];
|
||||
|
||||
/*TabBarSubItem *subItem1 = [TabBarSubItem tabBarSubItemWithName:@"Peppe"];
|
||||
TabBarSubItem *subItem2 = [TabBarSubItem tabBarSubItemWithName:@"Peppe1"];
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "TabBarSubItem.h"
|
||||
#import "TabBarPickerSubItemsView.h"
|
||||
|
||||
@class TabBarItem;
|
||||
|
||||
@ -25,14 +26,17 @@
|
||||
* Represents the image visible in picker when item is not selected.
|
||||
*/
|
||||
@property (nonatomic, strong) UIImage *image;
|
||||
|
||||
/**
|
||||
* Represents the image visible in picker when item is selected.
|
||||
*/
|
||||
@property (nonatomic, strong) UIImage *selectedImage;
|
||||
|
||||
/**
|
||||
* Represents the image visible in picker when item is highlited.
|
||||
*/
|
||||
@property (nonatomic, strong) UIImage *highlightedImage;
|
||||
|
||||
/**
|
||||
* Represents the color of picker item when is highlited.
|
||||
*/
|
||||
@ -42,11 +46,15 @@
|
||||
* Represents the name of the item that can be shown in picker.
|
||||
*/
|
||||
@property (nonatomic, strong) NSString *itemName;
|
||||
|
||||
/**
|
||||
* Represents the sub items that appeare when you select the item in picker.
|
||||
*/
|
||||
@property (nonatomic, strong) NSMutableArray *subItems;
|
||||
@property (nonatomic, strong) TabBarPickerSubItemsView *itemSubView;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, assign) id<TabBarItemDelegate> delegate;
|
||||
|
||||
/**
|
||||
@ -56,8 +64,13 @@
|
||||
*
|
||||
* @return <#return value description#>
|
||||
*/
|
||||
- (instancetype) initWithSubItems:(NSArray*) array;
|
||||
- (instancetype) initWithSubItemView:(TabBarPickerSubItemsView*) itemSubView;
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*
|
||||
* @param highlighted <#highlighted description#>
|
||||
*/
|
||||
- (void) setHighlighted:(BOOL) highlighted;
|
||||
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "NSString+HexColor.h"
|
||||
#import "UIButton+BackgroundColor.h"
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface TabBarItem()
|
||||
|
||||
@ -17,18 +18,27 @@
|
||||
@property (nonatomic, strong) UIButton *itemButton;
|
||||
@property (nonatomic) UIDeviceOrientation orientation;
|
||||
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||
@property (nonatomic, strong) UIView *switchBarView;
|
||||
@property (nonatomic, strong) UISwitch *itemSwich;
|
||||
@property (nonatomic, strong) UILabel *switchBarLabel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TabBarItem
|
||||
|
||||
- (instancetype) initWithSubItems:(NSArray*) array {
|
||||
- (instancetype) initWithSubItemView:(TabBarPickerSubItemsView*) itemSubView {
|
||||
|
||||
return [self initWithSubItemView:itemSubView needLocalization:NO];
|
||||
}
|
||||
|
||||
- (instancetype) initWithSubItemView:(TabBarPickerSubItemsView*) itemSubView needLocalization:(BOOL) needLocalitazion {
|
||||
self = [self initForAutoLayout];
|
||||
if (self) {
|
||||
NSAssert(array, @"SubItemsArray cannot be nil");
|
||||
NSAssert(itemSubView, @"itemSubView cannot be nil");
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
|
||||
|
||||
_orientation = [[UIDevice currentDevice] orientation];
|
||||
_itemSubView = itemSubView;
|
||||
|
||||
_itemButton = [[UIButton alloc] initForAutoLayout];
|
||||
[_itemButton addTarget:self action:@selector(itemButtonTapped) forControlEvents:UIControlEventTouchUpInside];
|
||||
@ -36,13 +46,6 @@
|
||||
|
||||
[self addSubview:_itemButton];
|
||||
|
||||
_subItems = [[NSMutableArray alloc] init];
|
||||
|
||||
for (NSObject *subItem in array) {
|
||||
if ([subItem isKindOfClass:[TabBarSubItem class]]) {
|
||||
[_subItems addObject:subItem];
|
||||
}
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -54,6 +57,7 @@
|
||||
[_itemButton autoCenterInSuperview];
|
||||
[_itemButton autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self];
|
||||
[_itemButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
|
||||
_didSetupConstraints = YES;
|
||||
}
|
||||
}
|
||||
@ -88,24 +92,26 @@
|
||||
|
||||
- (void) setHighlighted:(BOOL) highlighted {
|
||||
[_itemButton setHighlighted:highlighted];
|
||||
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isSelected]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isHighlighted]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isEnabled]]);
|
||||
NSLog(@"%ld",_itemButton.state);
|
||||
}
|
||||
|
||||
- (void) itemButtonTapped {
|
||||
if (_delegate && [_delegate respondsToSelector:@selector(tabBarItemSelected:)]) {
|
||||
[_delegate tabBarItemSelected:self];
|
||||
}
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isSelected]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isHighlighted]]);
|
||||
NSLog(@"%@",[NSNumber numberWithBool:[_itemButton isEnabled]]);
|
||||
NSLog(@"%ld",_itemButton.state);
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.002 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[_itemButton setHighlighted:YES];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.00001 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self setHighlighted:YES];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void)openSettings
|
||||
{
|
||||
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
|
||||
if (canOpenSettings) {
|
||||
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#import "TabBarPicker.h"
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "TabBarPickerSubItemsView.h"
|
||||
#import "MMCPSScrollView.h"
|
||||
#import "ToucheableScrollView.h"
|
||||
#import <UIView-Overlay/UIView+Overlay.h>
|
||||
#import "NSString+HexColor.h"
|
||||
|
||||
@ -24,7 +24,9 @@
|
||||
@property (nonatomic, strong) NSLayoutConstraint *hideConstraint;
|
||||
@property (nonatomic, strong) NSMutableArray *tabBarItemsConstraints;
|
||||
@property (nonatomic, strong) TabBarItem *selectedTabBarItem;
|
||||
@property (nonatomic, strong) MMCPSScrollView *subItemScrollView;
|
||||
|
||||
@property (nonatomic, strong) ToucheableScrollView *subItemScrollView;
|
||||
@property (assign, nonatomic) int totalPages;
|
||||
|
||||
@end
|
||||
|
||||
@ -46,7 +48,7 @@
|
||||
|
||||
self = [self initForAutoLayout];
|
||||
if (self) {
|
||||
|
||||
[self setUserInteractionEnabled:YES];
|
||||
_itemSpacing = 10;
|
||||
_layoutRelation = relation;
|
||||
_position = position;
|
||||
@ -77,47 +79,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
_subItemScrollView = [[MMCPSScrollView alloc] initForAutoLayout];
|
||||
[_subItemScrollView setType:MMCPSScrollHorizontal];
|
||||
[_subItemScrollView setMMCPSDelegate:self];
|
||||
_subItemScrollView = [[ToucheableScrollView alloc] initForAutoLayout];
|
||||
[_subItemScrollView setPagingEnabled:YES];
|
||||
[_subItemScrollView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
|
||||
[_subItemScrollView setUserInteractionEnabled:YES];
|
||||
|
||||
[self addSubview:_subItemScrollView];
|
||||
|
||||
if ([_tabBarItems count] > 0) {
|
||||
int i = 0;
|
||||
for (TabBarItem *item in _tabBarItems) {
|
||||
TabBarPickerSubItemsView *subItemSelector = [[TabBarPickerSubItemsView alloc] init];
|
||||
[subItemSelector setDelegate:self];
|
||||
switch (i) {
|
||||
case 0:
|
||||
[subItemSelector setBackgroundColor:[UIColor lightGrayColor]];
|
||||
break;
|
||||
case 1:{
|
||||
[subItemSelector setBackgroundColor:[UIColor redColor]];
|
||||
}
|
||||
break;
|
||||
case 2:{
|
||||
[subItemSelector setBackgroundColor:[UIColor greenColor]];
|
||||
}
|
||||
break;
|
||||
case 3: {
|
||||
[subItemSelector setBackgroundColor:[UIColor yellowColor]];
|
||||
}
|
||||
break;
|
||||
default:{
|
||||
[subItemSelector setBackgroundColor:[UIColor blueColor]];
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
[_subItemScrollView addSubview:subItemSelector];
|
||||
|
||||
[_subItemSelectors addObject:subItemSelector];
|
||||
}
|
||||
[_subItemScrollView setPageSize:1];
|
||||
}
|
||||
}
|
||||
|
||||
[self updateConstraintsIfNeeded];
|
||||
@ -185,23 +152,71 @@
|
||||
|
||||
[_tabBarItemsConstraints addObjectsFromArray:[_tabBarItems autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:_itemSpacing insetSpacing:YES matchedSizes:YES]];
|
||||
|
||||
|
||||
|
||||
[_subItemScrollView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
[_subItemScrollView autoSetDimension:ALDimensionHeight toSize:343];
|
||||
[_subItemScrollView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:[_tabBarItems firstObject]];
|
||||
[_subItemScrollView autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
|
||||
//[_subItemScrollView setPageSize:343];
|
||||
[_subItemScrollView setSegmentSize:[[UIScreen mainScreen] bounds].size.width];
|
||||
if ([_tabBarItems count] > 0) {
|
||||
int i = 0;
|
||||
|
||||
[_subItemSelectors autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES];
|
||||
[_subItemSelectors autoSetViewsDimension:ALDimensionHeight toSize:343];
|
||||
[_subItemSelectors autoSetViewsDimension:ALDimensionWidth toSize:[[UIScreen mainScreen] bounds].size.width];
|
||||
TabBarItem *prevItem;
|
||||
for (TabBarItem *item in _tabBarItems) {
|
||||
|
||||
[[_subItemSelectors firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
if ([item itemSubView]) {
|
||||
|
||||
[_subItemScrollView setContentSize:CGSizeMake([_subItemSelectors count]*[[UIScreen mainScreen] bounds].size.width , 343)];
|
||||
[[item itemSubView] setDelegate:self];
|
||||
[[item itemSubView] setTabBarItemReference:self];
|
||||
switch (i) {
|
||||
case 0:
|
||||
[[item itemSubView] setBackgroundColor:[UIColor lightGrayColor]];
|
||||
break;
|
||||
case 1:{
|
||||
[[item itemSubView] setBackgroundColor:[UIColor redColor]];
|
||||
}
|
||||
break;
|
||||
case 2:{
|
||||
[[item itemSubView] setBackgroundColor:[UIColor greenColor]];
|
||||
}
|
||||
break;
|
||||
case 3: {
|
||||
[[item itemSubView] setBackgroundColor:[UIColor yellowColor]];
|
||||
}
|
||||
break;
|
||||
default:{
|
||||
[[item itemSubView] setBackgroundColor:[UIColor blueColor]];
|
||||
}
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
[_subItemScrollView addSubview:[item itemSubView]];
|
||||
|
||||
[_subItemSelectors addObject:[item itemSubView]];
|
||||
|
||||
if (!prevItem) {
|
||||
// Align to contentView
|
||||
[pageLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft];
|
||||
} else {
|
||||
// Align to prev label
|
||||
[pageLabel autoConstrainAttribute:ALAttributeLeading toAttribute:ALAttributeTrailing ofView:prevLabel];
|
||||
}
|
||||
|
||||
if (i == pages - 1) {
|
||||
// Last page
|
||||
[pageLabel autoPinEdgeToSuperviewEdge:ALEdgeRight];
|
||||
}
|
||||
|
||||
prevItem = item;
|
||||
}
|
||||
}
|
||||
[_subItemScrollView setPageSize:1];
|
||||
}
|
||||
|
||||
//[_subItemSelectors autoDistributeViewsAlongAxis:ALAxisHorizontal alignedTo:ALAttributeHorizontal withFixedSpacing:0 insetSpacing:YES matchedSizes:YES];
|
||||
|
||||
//[[_subItemSelectors firstObject] autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
|
||||
//[_subItemScrollView layoutIfNeeded];
|
||||
|
||||
}
|
||||
break;
|
||||
@ -374,7 +389,7 @@
|
||||
}
|
||||
_selectedTabBarItem = selectedItem;
|
||||
|
||||
[_subItemScrollView scrollToPage:[_tabBarItems indexOfObject:_selectedTabBarItem]];
|
||||
[_subItemScrollView scrollToPage:[_tabBarItems indexOfObject:_selectedTabBarItem]+1];
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@ -7,8 +7,9 @@
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TabBarItem.h"
|
||||
|
||||
@class TabBarItem;
|
||||
@class TabBarSubItem;
|
||||
@class TabBarPickerSubItemsView;
|
||||
|
||||
typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
|
||||
@ -23,7 +24,7 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
|
||||
|
||||
@required
|
||||
|
||||
- (void) tabarPickerSubItemsView:(TabBarPickerSubItemsView*) tabarPickerSubItemsView didSelect:(TabBarItem*) item;
|
||||
- (void) tabarPickerSubItemsView:(TabBarPickerSubItemsView*) tabarPickerSubItemsView didSelectTabBarSubItem:(TabBarSubItem*) subItem forTabBarItem:(TabBarItem*) item;
|
||||
|
||||
@end
|
||||
|
||||
@ -33,6 +34,21 @@ typedef NS_ENUM(NSInteger, TabBarPickerSubItemsViewType) {
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, assign) id<TabBarPickerSubItemsViewDelegate> delegate;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic) BOOL needsLocalization;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong) UIView *localizationView;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong) TabBarItem *tabBarItemReference;
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems;
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization;
|
||||
|
||||
@end
|
||||
|
||||
@ -8,23 +8,83 @@
|
||||
|
||||
#import "TabBarPickerSubItemsView.h"
|
||||
#import <PureLayout/PureLayout.h>
|
||||
#import "TabBarItem.h"
|
||||
#import "NSString+HexColor.h"
|
||||
#import "SharedLocationManager.h"
|
||||
|
||||
@interface TabBarPickerSubItemsView()
|
||||
|
||||
@property (nonatomic, assign) BOOL didSetupConstraints;
|
||||
@property (nonatomic) TabBarPickerSubItemsViewType type;
|
||||
@property (nonatomic, strong) NSMutableArray *elementsArray;
|
||||
@property (nonatomic, strong) NSMutableArray *subItems;
|
||||
@property (nonatomic, strong) UIView *switchBarView;
|
||||
@property (nonatomic, strong) UISwitch *itemSwich;
|
||||
@property (nonatomic, strong) UILabel *switchBarLabel;
|
||||
@property (nonatomic, strong) UIButton *localizationButton;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TabBarPickerSubItemsView
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type andElements:(NSArray*) elements {
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems {
|
||||
return [self initWithType:type subItems:subItems needsLocalization:NO];
|
||||
}
|
||||
|
||||
- (instancetype) initWithType:(TabBarPickerSubItemsViewType) type subItems:(NSArray*) subItems needsLocalization:(BOOL) needsLocalization{
|
||||
|
||||
self = [self initForAutoLayout];
|
||||
|
||||
if (self) {
|
||||
[self setUserInteractionEnabled:YES];
|
||||
_type = type;
|
||||
_elementsArray = [[NSMutableArray alloc] initWithArray:elements];
|
||||
_needsLocalization = needsLocalization;
|
||||
_switchBarView = [[UIView alloc] initForAutoLayout];
|
||||
[_switchBarView setBackgroundColor:[@"f7f7f7" colorFromHex]];
|
||||
|
||||
_switchBarLabel = [[UILabel alloc] initForAutoLayout];
|
||||
[_switchBarLabel setTextColor:[@"999999" colorFromHex]];
|
||||
[_switchBarLabel setText:NSLocalizedString(@"Distance", @"")];
|
||||
[_switchBarView addSubview:_switchBarLabel];
|
||||
|
||||
_itemSwich = [[UISwitch alloc] initForAutoLayout];
|
||||
[_itemSwich setOnTintColor:[@"ff4e50" colorFromHex]];
|
||||
|
||||
[_itemSwich.layer setBorderWidth:2];
|
||||
[_itemSwich.layer setBorderColor:[[@"cccccc" colorFromHex] CGColor]];
|
||||
[_itemSwich.layer setCornerRadius:_itemSwich.frame.size.height/2];
|
||||
[_itemSwich setUserInteractionEnabled:YES];
|
||||
[_itemSwich addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
|
||||
[_switchBarView addSubview:_itemSwich];
|
||||
|
||||
if (_needsLocalization) {
|
||||
|
||||
_localizationView = [[UIView alloc] initForAutoLayout];
|
||||
[_localizationView setBackgroundColor:[UIColor purpleColor]];
|
||||
[_localizationView setAlpha:0];
|
||||
|
||||
|
||||
_localizationButton = [[UIButton alloc] initForAutoLayout];
|
||||
[_localizationButton setTitle:NSLocalizedString(@"ATTIVA LOCALIZZAZIONE DISPOSITIVO", @"") forState:UIControlStateNormal];
|
||||
[_localizationButton addTarget:self action:@selector(openSettings) forControlEvents:UIControlEventTouchUpInside];
|
||||
[_localizationButton setBackgroundColor:[UIColor whiteColor]];
|
||||
[_localizationButton.layer setBorderColor:[[@"ff4e50" colorFromHex] CGColor]];
|
||||
[_localizationButton.layer setBorderWidth:1];
|
||||
[_localizationButton setTitleColor:[@"ff4e50" colorFromHex] forState:UIControlStateNormal];
|
||||
[_localizationButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
|
||||
[_localizationButton.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:14]];
|
||||
|
||||
[_localizationView addSubview:_localizationButton];
|
||||
|
||||
[self addSubview:_localizationView];
|
||||
}
|
||||
|
||||
/*_subItems = [[NSMutableArray alloc] init];
|
||||
for (NSObject *subItem in subItems) {
|
||||
if ([subItem isKindOfClass:[TabBarSubItem class]]) {
|
||||
[_subItems addObject:subItem];
|
||||
}
|
||||
}*/
|
||||
[self addSubview:_switchBarView];
|
||||
}
|
||||
|
||||
[self updateConstraintsIfNeeded];
|
||||
@ -35,13 +95,77 @@
|
||||
|
||||
- (void) layoutSubviews {
|
||||
|
||||
[UIView animateWithDuration:0.5 animations:^{
|
||||
[_localizationView setAlpha:[[NSNumber numberWithBool:[[SharedLocationManager sharedManager] localizationIsAuthorized]] floatValue]];
|
||||
}];
|
||||
|
||||
if (!_didSetupConstraints) {
|
||||
|
||||
[self autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
|
||||
[self autoMatchDimension:ALDimensionHeight toDimension:ALDimensionHeight ofView:self.superview withOffset:0 relation:NSLayoutRelationEqual];
|
||||
|
||||
[_switchBarView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self.superview];
|
||||
[_switchBarView autoSetDimension:ALDimensionHeight toSize:40];
|
||||
[_switchBarView autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self];
|
||||
[_switchBarView autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
|
||||
[_switchBarLabel autoPinEdge:ALEdgeLeft toEdge:ALEdgeLeft ofView:self withOffset:20];
|
||||
[_switchBarLabel autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
|
||||
[_itemSwich autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:_switchBarView withOffset:-20];
|
||||
[_itemSwich autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
|
||||
[_localizationView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:_itemSwich withOffset:4];
|
||||
[_localizationView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:self];
|
||||
[_localizationView autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];
|
||||
|
||||
[_localizationButton autoAlignAxisToSuperviewAxis:ALAxisHorizontal];
|
||||
[_localizationButton autoAlignAxisToSuperviewAxis:ALAxisVertical];
|
||||
[_localizationButton autoSetDimension:ALDimensionHeight toSize:44 relation:NSLayoutRelationLessThanOrEqual];
|
||||
[_localizationButton autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self withMultiplier:0.8];
|
||||
|
||||
_didSetupConstraints = YES;
|
||||
}
|
||||
NSLog(@"%f %f",self.frame.size.width,self.frame.size.height);
|
||||
NSLog(@"%f %f",_switchBarView.frame.size.width,_switchBarView.frame.size.height);
|
||||
[_localizationButton.layer setCornerRadius:_localizationButton.frame.size.height/2];
|
||||
}
|
||||
|
||||
- (void) enableLocalizationWithView:(UIView *) localizationView {
|
||||
_needsLocalization = YES;
|
||||
_localizationView = localizationView;
|
||||
|
||||
[self addSubview:_localizationView];
|
||||
}
|
||||
|
||||
|
||||
- (void)openSettings
|
||||
{
|
||||
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
|
||||
if (canOpenSettings) {
|
||||
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)changeSwitch:(UISwitch*)sender{
|
||||
|
||||
if([sender isOn]){
|
||||
NSLog(@"Switch is ON");
|
||||
} else{
|
||||
NSLog(@"Switch is OFF");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
|
||||
{
|
||||
[super touchesEnded: touches withEvent: event];
|
||||
}
|
||||
|
||||
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
|
||||
[super touchesBegan: touches withEvent:event];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@ -12,7 +12,8 @@
|
||||
|
||||
@property (nonatomic, strong) NSString *name;
|
||||
@property (nonatomic, strong) UIButton *subItemButton;
|
||||
@property (nonatomic, strong) id value;
|
||||
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name;
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id) value;;
|
||||
|
||||
@end
|
||||
|
||||
@ -19,28 +19,28 @@
|
||||
@implementation TabBarSubItem
|
||||
|
||||
|
||||
- (instancetype) initWithName:(NSString *) name {
|
||||
- (instancetype) initWithName:(NSString *) name andValue:(id)value {
|
||||
|
||||
self = [self initForAutoLayout];
|
||||
if (self) {
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
|
||||
//[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
|
||||
|
||||
_name = name;
|
||||
|
||||
_subItemButton = [[UIButton alloc] initForAutoLayout];
|
||||
[_subItemButton setTitle:_name forState:UIControlStateNormal];
|
||||
_value = value;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name {
|
||||
return [[self alloc] initWithName:name];
|
||||
+ (instancetype) tabBarSubItemWithName:(NSString*)name andValue:(id)value {
|
||||
return [[self alloc] initWithName:name andValue:value];
|
||||
}
|
||||
|
||||
- (void) setName:(NSString *)name {
|
||||
_name = name;
|
||||
[_subItemButton setTitle:name forState:UIControlStateNormal];
|
||||
[_subItemButton setTitle:_name forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
|
||||
if (self) {
|
||||
self.backgroundColor = [UIColor whiteColor];
|
||||
[self setUserInteractionEnabled:YES];
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -291,6 +292,7 @@
|
||||
|
||||
- (void)addSubview:(UIView *)view {
|
||||
[super addSubview:view];
|
||||
[view setUserInteractionEnabled:YES];
|
||||
|
||||
int currentLowestPoint = [self CGRectOrigin:_bottomComponent] + [self CGRectSize:_bottomComponent];
|
||||
int viewLowestPoint = [self frameOrigin:view] + [self frameSize:view];
|
||||
@ -318,4 +320,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
|
||||
{
|
||||
// If not dragging, send event to next responder
|
||||
if (!self.dragging) {
|
||||
[self.nextResponder.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
else
|
||||
[super touchesEnded: touches withEvent: event];
|
||||
|
||||
}
|
||||
|
||||
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||
|
||||
if (!self.dragging) {
|
||||
[self.nextResponder.nextResponder touchesBegan: touches withEvent:event];
|
||||
}
|
||||
else
|
||||
[super touchesBegan: touches withEvent:event];
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
23
Pod/Classes/Vendor/SharedLocationManager/SharedLocationManager.h
vendored
Executable file
23
Pod/Classes/Vendor/SharedLocationManager/SharedLocationManager.h
vendored
Executable file
@ -0,0 +1,23 @@
|
||||
//
|
||||
// SharedLocationManager.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 15/07/15.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreLocation/CoreLocation.h>
|
||||
|
||||
@interface SharedLocationManager : NSObject <CLLocationManagerDelegate>{
|
||||
CLLocationManager *locationManager;
|
||||
CLLocation *currentLocation;
|
||||
}
|
||||
|
||||
+ (id) sharedManager;
|
||||
- (void) setCurrentLocation;
|
||||
- (CLLocation*) getCurrentLocation;
|
||||
- (BOOL) locationIsSet;
|
||||
- (BOOL) localizationIsAuthorized;
|
||||
- (CLAuthorizationStatus) localizationAuthorizationStatus;
|
||||
|
||||
@end
|
||||
78
Pod/Classes/Vendor/SharedLocationManager/SharedLocationManager.m
vendored
Executable file
78
Pod/Classes/Vendor/SharedLocationManager/SharedLocationManager.m
vendored
Executable file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// SharedLocationManager.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 15/07/15.
|
||||
//
|
||||
|
||||
#import "SharedLocationManager.h"
|
||||
|
||||
@implementation SharedLocationManager
|
||||
+ (id)sharedManager {
|
||||
static SharedLocationManager *sharedMyManager = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
sharedMyManager = [[self alloc] init];
|
||||
});
|
||||
return sharedMyManager;
|
||||
}
|
||||
|
||||
- (id)init {
|
||||
if (self = [super init]) {
|
||||
locationManager = [[CLLocationManager alloc] init];
|
||||
locationManager.delegate = self;
|
||||
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
|
||||
if([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0)
|
||||
{
|
||||
[CLLocationManager authorizationStatus];
|
||||
}
|
||||
else {
|
||||
[locationManager requestWhenInUseAuthorization];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (void)setCurrentLocation {
|
||||
|
||||
[locationManager startUpdatingLocation];
|
||||
}
|
||||
#pragma mark - CLLocationManagerDelegate
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
|
||||
{
|
||||
[locationManager stopUpdatingLocation];
|
||||
}
|
||||
|
||||
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
|
||||
{
|
||||
if (newLocation != nil) {
|
||||
currentLocation = newLocation;
|
||||
}
|
||||
[locationManager stopUpdatingLocation];
|
||||
}
|
||||
|
||||
-(BOOL)locationIsSet {
|
||||
if(currentLocation != nil)
|
||||
return YES;
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
-(CLLocation*)getCurrentLocation {
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
- (BOOL) localizationIsAuthorized {
|
||||
if ( [CLLocationManager locationServicesEnabled] == NO || [self localizationAuthorizationStatus] == kCLAuthorizationStatusDenied)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (CLAuthorizationStatus) localizationAuthorizationStatus {
|
||||
return [CLLocationManager authorizationStatus];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
13
Pod/Classes/Vendor/TouchableScrollView/ToucheableScrollView.h
vendored
Executable file
13
Pod/Classes/Vendor/TouchableScrollView/ToucheableScrollView.h
vendored
Executable file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// ToucheableScrollView.m
|
||||
//
|
||||
//
|
||||
// Created by Mario Nolassi on 11/16/11.
|
||||
// Copyright (c) 2011 meedori. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface ToucheableScrollView : UIScrollView
|
||||
|
||||
@end
|
||||
44
Pod/Classes/Vendor/TouchableScrollView/ToucheableScrollView.m
vendored
Executable file
44
Pod/Classes/Vendor/TouchableScrollView/ToucheableScrollView.m
vendored
Executable file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// ToucheableScrollView.m
|
||||
//
|
||||
//
|
||||
// Created by Mario Nolassi on 11/16/11.
|
||||
// Copyright (c) 2011 meedori. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ToucheableScrollView.h"
|
||||
|
||||
@implementation ToucheableScrollView
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
|
||||
{
|
||||
// If not dragging, send event to next responder
|
||||
if (!self.dragging) {
|
||||
if ([self.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
|
||||
[self.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
if ([self.nextResponder.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
|
||||
[self.nextResponder.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
if ([self.nextResponder.nextResponder.nextResponder respondsToSelector:@selector(touchesEnded:withEvent:)]) {
|
||||
[self.nextResponder.nextResponder.nextResponder touchesEnded: touches withEvent:event];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[super touchesEnded: touches withEvent: event];
|
||||
}
|
||||
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user