├── ReadmeResource
├── 1.gif
├── 2.jpeg
├── 3.png
├── 4.gif
├── 5.png
├── 6.gif
├── license.png
├── support.png
├── introduce.png
└── platform.png
├── Example
├── Example
│ ├── imgae
│ │ ├── 11.png
│ │ └── 22.png
│ ├── MoreViewController.h
│ ├── ViewController.h
│ ├── Masonry
│ │ ├── MASLayoutConstraint.m
│ │ ├── NSLayoutConstraint+MASDebugAdditions.h
│ │ ├── MASLayoutConstraint.h
│ │ ├── MASCompositeConstraint.h
│ │ ├── ViewController+MASAdditions.h
│ │ ├── ViewController+MASAdditions.m
│ │ ├── Masonry.h
│ │ ├── Info.plist
│ │ ├── NSArray+MASShorthandAdditions.h
│ │ ├── MASViewAttribute.m
│ │ ├── MASViewAttribute.h
│ │ ├── MASViewConstraint.h
│ │ ├── NSArray+MASAdditions.m
│ │ ├── NSArray+MASAdditions.h
│ │ ├── MASConstraint+Private.h
│ │ ├── View+MASAdditions.h
│ │ ├── View+MASShorthandAdditions.h
│ │ ├── MASCompositeConstraint.m
│ │ ├── MASConstraintMaker.h
│ │ ├── View+MASAdditions.m
│ │ ├── NSLayoutConstraint+MASDebugAdditions.m
│ │ ├── MASUtilities.h
│ │ ├── MASConstraint.h
│ │ ├── MASConstraint.m
│ │ ├── MASConstraintMaker.m
│ │ └── MASViewConstraint.m
│ ├── AppDelegate.h
│ ├── main.m
│ ├── Globals.h
│ ├── Assets.xcassets
│ │ └── AppIcon.appiconset
│ │ │ └── Contents.json
│ ├── Info.plist
│ ├── Base.lproj
│ │ ├── Main.storyboard
│ │ └── LaunchScreen.storyboard
│ ├── AppDelegate.m
│ ├── MoreViewController.m
│ └── ViewController.m
└── Example.xcodeproj
│ ├── xcuserdata
│ └── Balzac.xcuserdatad
│ │ ├── xcdebugger
│ │ └── Breakpoints_v2.xcbkptlist
│ │ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── Example.xcscheme
│ ├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── Balzac.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
│ └── project.pbxproj
├── WHGradientHelper
├── WHGradientHelper.h
└── WHGradientHelper.m
├── .gitignore
└── README.md
/ReadmeResource/1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/1.gif
--------------------------------------------------------------------------------
/ReadmeResource/2.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/2.jpeg
--------------------------------------------------------------------------------
/ReadmeResource/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/3.png
--------------------------------------------------------------------------------
/ReadmeResource/4.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/4.gif
--------------------------------------------------------------------------------
/ReadmeResource/5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/5.png
--------------------------------------------------------------------------------
/ReadmeResource/6.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/6.gif
--------------------------------------------------------------------------------
/ReadmeResource/license.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/license.png
--------------------------------------------------------------------------------
/ReadmeResource/support.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/support.png
--------------------------------------------------------------------------------
/Example/Example/imgae/11.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/Example/Example/imgae/11.png
--------------------------------------------------------------------------------
/Example/Example/imgae/22.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/Example/Example/imgae/22.png
--------------------------------------------------------------------------------
/ReadmeResource/introduce.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/introduce.png
--------------------------------------------------------------------------------
/ReadmeResource/platform.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/ReadmeResource/platform.png
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/xcuserdata/Balzac.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.xcworkspace/xcuserdata/Balzac.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/whbalzac/WHGradientHelper/HEAD/Example/Example.xcodeproj/project.xcworkspace/xcuserdata/Balzac.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/Example/Example/MoreViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // MoreViewController.h
3 | // Example
4 | //
5 | // Created by whbalzac on 3/27/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MoreViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Example/Example/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASLayoutConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASLayoutConstraint.h"
10 |
11 | @implementation MASLayoutConstraint
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/Example/Example/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/Example/Example/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/NSLayoutConstraint+MASDebugAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * makes debug and log output of NSLayoutConstraints more readable
13 | */
14 | @interface NSLayoutConstraint (MASDebugAdditions)
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASLayoutConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * When you are debugging or printing the constraints attached to a view this subclass
13 | * makes it easier to identify which constraints have been created via Masonry
14 | */
15 | @interface MASLayoutConstraint : NSLayoutConstraint
16 |
17 | /**
18 | * a key to associate with this constraint
19 | */
20 | @property (nonatomic, strong) id mas_key;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASCompositeConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | /**
13 | * A group of MASConstraint objects
14 | */
15 | @interface MASCompositeConstraint : MASConstraint
16 |
17 | /**
18 | * Creates a composite with a predefined array of children
19 | *
20 | * @param children child MASConstraints
21 | *
22 | * @return a composite constraint
23 | */
24 | - (id)initWithChildren:(NSArray *)children;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/xcuserdata/Balzac.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | Example.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | A52B76C51E7FBA6500938AEA
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/ViewController+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Craig Siemens on 2015-06-23.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | #ifdef MAS_VIEW_CONTROLLER
14 |
15 | @interface MAS_VIEW_CONTROLLER (MASAdditions)
16 |
17 | /**
18 | * following properties return a new MASViewAttribute with appropriate UILa 8youtGuide and NSLayoutAttribute
19 | */
20 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide;
21 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide;
22 |
23 | @end
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/ViewController+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Craig Siemens on 2015-06-23.
6 | //
7 | //
8 |
9 | #import "ViewController+MASAdditions.h"
10 |
11 | #ifdef MAS_VIEW_CONTROLLER
12 |
13 | @implementation MAS_VIEW_CONTROLLER (MASAdditions)
14 |
15 | - (MASViewAttribute *)mas_topLayoutGuide {
16 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
17 | }
18 |
19 | - (MASViewAttribute *)mas_bottomLayoutGuide {
20 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop];
21 | }
22 |
23 | @end
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/Masonry.h:
--------------------------------------------------------------------------------
1 | //
2 | // Masonry.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for Masonry.
12 | FOUNDATION_EXPORT double MasonryVersionNumber;
13 |
14 | //! Project version string for Masonry.
15 | FOUNDATION_EXPORT const unsigned char MasonryVersionString[];
16 |
17 | #import "MASUtilities.h"
18 | #import "View+MASAdditions.h"
19 | #import "View+MASShorthandAdditions.h"
20 | #import "ViewController+MASAdditions.h"
21 | #import "NSArray+MASAdditions.h"
22 | #import "NSArray+MASShorthandAdditions.h"
23 | #import "MASConstraint.h"
24 | #import "MASCompositeConstraint.h"
25 | #import "MASViewAttribute.h"
26 | #import "MASViewConstraint.h"
27 | #import "MASConstraintMaker.h"
28 | #import "MASLayoutConstraint.h"
29 | #import "NSLayoutConstraint+MASDebugAdditions.h"
30 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | com.cloudling.$(PRODUCT_NAME:rfc1034identifier)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/NSArray+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand array additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface NSArray (MASShorthandAdditions)
18 |
19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
22 |
23 | @end
24 |
25 | @implementation NSArray (MASShorthandAdditions)
26 |
27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
28 | return [self mas_makeConstraints:block];
29 | }
30 |
31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
32 | return [self mas_updateConstraints:block];
33 | }
34 |
35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
36 | return [self mas_remakeConstraints:block];
37 | }
38 |
39 | @end
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/Example/Example/Globals.h:
--------------------------------------------------------------------------------
1 | //
2 | // Globals.h
3 | // Example
4 | //
5 | // Created by whbalzac on 3/21/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #ifndef Globals_h
10 | #define Globals_h
11 |
12 | #define UIColorFromRGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
13 | #define UIColorFronHSB(h,s,b) [UIColor colorWithHue:h saturation:s brightness:b alpha:1.0f]
14 |
15 | #define kColor1 UIColorFromRGBA(107,127,255,1.0f)
16 | #define kColor2 UIColorFromRGBA(145,62,245,1.0f)
17 | #define kColor3 UIColorFromRGBA(242,63,159,0.8f)
18 | #define kColor4 UIColorFromRGBA(255,164,221,0.8f)
19 | #define kColor5 UIColorFromRGBA(193,44,255,1.0f)
20 | #define kColor6 UIColorFromRGBA(227,25,168,1.0f)
21 | #define kColor7 UIColorFromRGBA(107,127,255,1.0f)
22 | #define kColor8 UIColorFromRGBA(145,62,245,1.0f)
23 | #define kColor9 UIColorFromRGBA(255,19,183,1.0f)
24 | #define kColor10 UIColorFromRGBA(255,31,74,1.0f)
25 |
26 | #define kColor11 UIColorFromRGBA(153, 70, 255, 0.8f)
27 | #define kColor12 UIColorFromRGBA(98, 168, 250, 0.8f)
28 |
29 |
30 | #endif /* Globals_h */
31 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASViewAttribute.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASAttribute.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 |
11 | @implementation MASViewAttribute
12 |
13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute {
14 | self = [self initWithView:view item:view layoutAttribute:layoutAttribute];
15 | return self;
16 | }
17 |
18 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute {
19 | self = [super init];
20 | if (!self) return nil;
21 |
22 | _view = view;
23 | _item = item;
24 | _layoutAttribute = layoutAttribute;
25 |
26 | return self;
27 | }
28 |
29 | - (BOOL)isSizeAttribute {
30 | return self.layoutAttribute == NSLayoutAttributeWidth
31 | || self.layoutAttribute == NSLayoutAttributeHeight;
32 | }
33 |
34 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute {
35 | if ([viewAttribute isKindOfClass:self.class]) {
36 | return self.view == viewAttribute.view
37 | && self.layoutAttribute == viewAttribute.layoutAttribute;
38 | }
39 | return [super isEqual:viewAttribute];
40 | }
41 |
42 | - (NSUInteger)hash {
43 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute;
44 | }
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASViewAttribute.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASAttribute.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * An immutable tuple which stores the view and the related NSLayoutAttribute.
13 | * Describes part of either the left or right hand side of a constraint equation
14 | */
15 | @interface MASViewAttribute : NSObject
16 |
17 | /**
18 | * The view which the reciever relates to. Can be nil if item is not a view.
19 | */
20 | @property (nonatomic, weak, readonly) MAS_VIEW *view;
21 |
22 | /**
23 | * The item which the reciever relates to.
24 | */
25 | @property (nonatomic, weak, readonly) id item;
26 |
27 | /**
28 | * The attribute which the reciever relates to
29 | */
30 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute;
31 |
32 | /**
33 | * Convenience initializer.
34 | */
35 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute;
36 |
37 | /**
38 | * The designated initializer.
39 | */
40 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute;
41 |
42 | /**
43 | * Determine whether the layoutAttribute is a size attribute
44 | *
45 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight
46 | */
47 | - (BOOL)isSizeAttribute;
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASViewConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 | #import "MASUtilities.h"
13 |
14 | /**
15 | * A single constraint.
16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view
17 | */
18 | @interface MASViewConstraint : MASConstraint
19 |
20 | /**
21 | * First item/view and first attribute of the NSLayoutConstraint
22 | */
23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;
24 |
25 | /**
26 | * Second item/view and second attribute of the NSLayoutConstraint
27 | */
28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;
29 |
30 | /**
31 | * initialises the MASViewConstraint with the first part of the equation
32 | *
33 | * @param firstViewAttribute view.mas_left, view.mas_width etc.
34 | *
35 | * @return a new view constraint
36 | */
37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute;
38 |
39 | /**
40 | * Returns all MASViewConstraints installed with this view as a first item.
41 | *
42 | * @param view A view to retrieve constraints for.
43 | *
44 | * @return An array of MASViewConstraints.
45 | */
46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/NSArray+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.m
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 | #import "View+MASAdditions.h"
11 |
12 | @implementation NSArray (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block {
15 | NSMutableArray *constraints = [NSMutableArray array];
16 | for (MAS_VIEW *view in self) {
17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]];
19 | }
20 | return constraints;
21 | }
22 |
23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block {
24 | NSMutableArray *constraints = [NSMutableArray array];
25 | for (MAS_VIEW *view in self) {
26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]];
28 | }
29 | return constraints;
30 | }
31 |
32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
33 | NSMutableArray *constraints = [NSMutableArray array];
34 | for (MAS_VIEW *view in self) {
35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]];
37 | }
38 | return constraints;
39 | }
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/Example/Example/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | Grandient
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/Example/Example/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Example/Example/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/NSArray+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.h
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | @interface NSArray (MASAdditions)
14 |
15 | /**
16 | * Creates a MASConstraintMaker with each view in the callee.
17 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view
18 | *
19 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
20 | *
21 | * @return Array of created MASConstraints
22 | */
23 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
24 |
25 | /**
26 | * Creates a MASConstraintMaker with each view in the callee.
27 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
28 | * If an existing constraint exists then it will be updated instead.
29 | *
30 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
31 | *
32 | * @return Array of created/updated MASConstraints
33 | */
34 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
35 |
36 | /**
37 | * Creates a MASConstraintMaker with each view in the callee.
38 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
39 | * All constraints previously installed for the views will be removed.
40 | *
41 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
42 | *
43 | * @return Array of created/updated MASConstraints
44 | */
45 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
46 |
47 | @end
48 |
--------------------------------------------------------------------------------
/WHGradientHelper/WHGradientHelper.h:
--------------------------------------------------------------------------------
1 | //
2 | // WHGradientHelper.h
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #define kDefaultWidth 200
12 | #define kDefaultHeight 200
13 |
14 | typedef NS_ENUM(NSInteger, WHGradientDirection) {
15 | WHLinearGradientDirectionLevel, //AC - BD
16 | WHLinearGradientDirectionVertical, //AB - CD
17 | WHLinearGradientDirectionUpwardDiagonalLine, //A - D
18 | WHLinearGradientDirectionDownDiagonalLine, //C - B
19 | };
20 | // A B
21 | // _________
22 | // | |
23 | // | |
24 | // ---------
25 | // C D
26 |
27 | @interface WHGradientHelper : NSObject
28 |
29 | // Linear Gradient
30 | + (UIImage *)getLinearGradientImage:(UIColor *)startColor and:(UIColor *)endColor directionType:(WHGradientDirection)directionType;/* CGSizeMake(kDefaultWidth, kDefaultHeight) */
31 | + (UIImage *)getLinearGradientImage:(UIColor *)startColor and:(UIColor *)endColor directionType:(WHGradientDirection)directionType option:(CGSize)size;
32 |
33 | // Radial Gradient
34 | + (UIImage *)getRadialGradientImage:(UIColor *)centerColor and:(UIColor *)outColor;/* raduis = kDefaultWidth / 2 */
35 | + (UIImage *)getRadialGradientImage:(UIColor *)centerColor and:(UIColor *)outColor option:(CGSize)size;
36 |
37 | // ChromatoAnimation
38 | + (void)addGradientChromatoAnimation:(UIView *)view;
39 |
40 | // LableText LinearGradient and ChromatoAnimation
41 | + (void)addLinearGradientForLableText:(UIView *)parentView lable:(UILabel *)lable start:(UIColor *)startColor and:(UIColor *)endColor; /* don't need call 'addSubview:' for lable */
42 | + (void)addGradientChromatoAnimationForLableText:(UIView *)parentView lable:(UILabel *)lable; /* don't need call 'addSubview:' for lable */
43 |
44 | @end
45 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASConstraint+Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint+Private.h
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 29/04/14.
6 | // Copyright (c) 2014 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 |
11 | @protocol MASConstraintDelegate;
12 |
13 |
14 | @interface MASConstraint ()
15 |
16 | /**
17 | * Whether or not to check for an existing constraint instead of adding constraint
18 | */
19 | @property (nonatomic, assign) BOOL updateExisting;
20 |
21 | /**
22 | * Usually MASConstraintMaker but could be a parent MASConstraint
23 | */
24 | @property (nonatomic, weak) id delegate;
25 |
26 | /**
27 | * Based on a provided value type, is equal to calling:
28 | * NSNumber - setOffset:
29 | * NSValue with CGPoint - setPointOffset:
30 | * NSValue with CGSize - setSizeOffset:
31 | * NSValue with MASEdgeInsets - setInsets:
32 | */
33 | - (void)setLayoutConstantWithValue:(NSValue *)value;
34 |
35 | @end
36 |
37 |
38 | @interface MASConstraint (Abstract)
39 |
40 | /**
41 | * Sets the constraint relation to given NSLayoutRelation
42 | * returns a block which accepts one of the following:
43 | * MASViewAttribute, UIView, NSValue, NSArray
44 | * see readme for more details.
45 | */
46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation;
47 |
48 | /**
49 | * Override to set a custom chaining behaviour
50 | */
51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
52 |
53 | @end
54 |
55 |
56 | @protocol MASConstraintDelegate
57 |
58 | /**
59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example
60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks
61 | */
62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint;
63 |
64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .orig
2 | .vscode/
3 | Pods/
4 | Podfile.lock
5 | .xcscheme
6 |
7 | *.DS_Store
8 | .AppleDouble
9 | .LSOverride
10 |
11 | # Icon must end with two \r
12 | Icon
13 |
14 |
15 | # Thumbnails
16 | ._*
17 |
18 | # Files that might appear in the root of a volume
19 | .DocumentRevisions-V100
20 | .fseventsd
21 | .Spotlight-V100
22 | .TemporaryItems
23 | .Trashes
24 | .VolumeIcon.icns
25 | .com.apple.timemachine.donotpresent
26 |
27 | # Directories potentially created on remote AFP share
28 | .AppleDB
29 | .AppleDesktop
30 | Network Trash Folder
31 | Temporary Items
32 | .apdisk
33 |
34 | # Xcode
35 | #
36 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
37 |
38 | ## Build generated
39 | build/
40 | DerivedData/
41 |
42 | ## Various settings
43 | *.pbxuser
44 | !default.pbxuser
45 | *.mode1v3
46 | !default.mode1v3
47 | *.mode2v3
48 | !default.mode2v3
49 | *.perspectivev3
50 | !default.perspectivev3
51 | xcuserdata/
52 |
53 | ## Other
54 | *.moved-aside
55 | *.xcuserstate
56 |
57 | ## Obj-C/Swift specific
58 | *.hmap
59 | *.ipa
60 | *.dSYM.zip
61 | *.dSYM
62 |
63 | # CocoaPods
64 | #
65 | # We recommend against adding the Pods directory to your .gitignore. However
66 | # you should judge for yourself, the pros and cons are mentioned at:
67 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
68 | #
69 | # Pods/
70 |
71 | # Carthage
72 | #
73 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
74 | # Carthage/Checkouts
75 |
76 | Carthage/Build
77 |
78 | # fastlane
79 | #
80 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
81 | # screenshots whenever they are needed.
82 | # For more information about the recommended setup visit:
83 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
84 |
85 | fastlane/report.xml
86 | fastlane/screenshots
87 |
88 | # Code Injection
89 | #
90 | # After new code Injection tools there's a generated folder /iOSInjectionProject
91 | # https://github.com/johnno1962/injectionforxcode
92 |
93 | iOSInjectionProject/
94 |
95 | */xcuserdata/
96 | *.orig
97 | *.xcworkspace/
--------------------------------------------------------------------------------
/Example/Example/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import "ViewController.h"
11 |
12 | @interface AppDelegate ()
13 |
14 | @end
15 |
16 | @implementation AppDelegate
17 |
18 |
19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
20 | // Override point for customization after application launch.
21 |
22 | self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];
23 |
24 | return YES;
25 | }
26 |
27 |
28 | - (void)applicationWillResignActive:(UIApplication *)application {
29 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
30 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
31 | }
32 |
33 |
34 | - (void)applicationDidEnterBackground:(UIApplication *)application {
35 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
36 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
37 | }
38 |
39 |
40 | - (void)applicationWillEnterForeground:(UIApplication *)application {
41 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
42 | }
43 |
44 |
45 | - (void)applicationDidBecomeActive:(UIApplication *)application {
46 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
47 | }
48 |
49 |
50 | - (void)applicationWillTerminate:(UIApplication *)application {
51 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
52 | }
53 |
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/Example/Example/MoreViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // MoreViewController.m
3 | // Example
4 | //
5 | // Created by whbalzac on 3/27/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import "MoreViewController.h"
10 | #import "WHGradientHelper.h"
11 | #import "Globals.h"
12 | #import "Masonry.h"
13 |
14 | @interface MoreViewController ()
15 |
16 | @end
17 |
18 | @implementation MoreViewController
19 |
20 | - (void)viewDidLoad {
21 | [super viewDidLoad];
22 | // Do any additional setup after loading the view.
23 |
24 | self.view.backgroundColor = [UIColor whiteColor];
25 |
26 | UIImageView *imgViewLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Logo111.png"]];
27 | [self.view addSubview:imgViewLogo];
28 | [imgViewLogo mas_makeConstraints:^(MASConstraintMaker *make) {
29 | make.top.mas_equalTo(self.view.mas_top).offset(100);
30 | make.centerX.mas_equalTo(self.view);
31 | make.height.mas_equalTo(128 * 0.8);
32 | make.width.mas_equalTo(626 * 0.8);
33 | }];
34 |
35 | UIImageView *imgLable = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"11.png"]];
36 | imgLable.contentMode = UIViewContentModeScaleToFill;
37 | [imgViewLogo addSubview:imgLable];
38 | [imgLable mas_makeConstraints:^(MASConstraintMaker *make) {
39 | make.edges.mas_equalTo(imgViewLogo);
40 | }];
41 |
42 | [self.view setNeedsLayout];
43 | [self.view layoutIfNeeded];
44 |
45 |
46 | [WHGradientHelper addGradientChromatoAnimation:imgViewLogo];
47 |
48 |
49 | // lable
50 | UILabel* lable1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, 375, 50)];
51 | lable1.textAlignment = NSTextAlignmentCenter;
52 | lable1.text = @"交流故事,沟通想法";
53 | lable1.font = [UIFont systemFontOfSize:28];
54 | [WHGradientHelper addLinearGradientForLableText:self.view lable:lable1 start:[UIColor blueColor] and:[UIColor greenColor]];
55 |
56 | UILabel* lable2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 440, 375, 50)];
57 | lable2.textAlignment = NSTextAlignmentCenter;
58 | lable2.text = @"交流故事,沟通想法";
59 | lable2.font = [UIFont systemFontOfSize:28];
60 | [WHGradientHelper addGradientChromatoAnimationForLableText:self.view lable:lable2];
61 |
62 |
63 |
64 | self.view.userInteractionEnabled = YES;
65 | UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissBtn:)];
66 | tapRecognizer.numberOfTapsRequired = 1;
67 | [self.view addGestureRecognizer:tapRecognizer];
68 | }
69 |
70 | #pragma mark - buttonAction
71 | - (void)dismissBtn:(UITapGestureRecognizer *)gesture
72 | {
73 | [self dismissViewControllerAnimated:YES completion:nil];
74 | }
75 |
76 | @end
77 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 | ## WHGradientHelper
10 | iOS渐变,支持——线性渐变,径向渐变,渐变动画,lable字体渐变,lable字体渐变动画
11 |
12 | #### 最终效果:
13 |
14 |
15 |
16 | - [x] 线性渐变
17 | - [x] 径向渐变
18 | - [x] 渐变动画
19 | - [x] Lable字体渐变
20 | - [x] Lable字体渐变动画
21 |
22 | #### 1. 线性渐变(Linear Gradient)
23 | “线性渐变”按照渐变方向分成4种类型,分别是:
24 |
25 | ```objective-c
26 | typedef NS_ENUM(NSInteger, WHGradientDirection) {
27 | WHLinearGradientDirectionLevel, //AC - BD
28 | WHLinearGradientDirectionVertical, //AB - CD
29 | WHLinearGradientDirectionUpwardDiagonalLine, //A - D
30 | WHLinearGradientDirectionDownDiagonalLine, //C - B
31 | };
32 | // A B
33 | // _________
34 | // | |
35 | // | |
36 | // ---------
37 | // C D
38 | ```
39 |
40 |
41 |
42 | #### 2. 径向渐变(Radial Gradient)
43 |
44 |
45 |
46 | #### 3. 渐变动画(ChromatoAnimation)
47 |
48 |
49 |
50 | #### 4. Lable字体渐变
51 |
52 |
53 |
54 | #### 5. Lable字体渐变动画
55 |
56 |
57 |
58 |
59 | ## WHGradientHelper头文件及使用
60 |
61 | ```objective-c
62 | #import
63 |
64 | #define kDefaultWidth 200
65 | #define kDefaultHeight 200
66 |
67 | typedef NS_ENUM(NSInteger, WHGradientDirection) {
68 | WHLinearGradientDirectionLevel, //AC - BD
69 | WHLinearGradientDirectionVertical, //AB - CD
70 | WHLinearGradientDirectionUpwardDiagonalLine, //A - D
71 | WHLinearGradientDirectionDownDiagonalLine, //C - B
72 | };
73 | // A B
74 | // _________
75 | // | |
76 | // | |
77 | // ---------
78 | // C D
79 |
80 | @interface WHGradientHelper : NSObject
81 |
82 | // Linear Gradient
83 | + (UIImage *)getLinearGradientImage:(UIColor *)startColor and:(UIColor *)endColor directionType:(WHGradientDirection)directionType;/* CGSizeMake(kDefaultWidth, kDefaultHeight) */
84 | + (UIImage *)getLinearGradientImage:(UIColor *)startColor and:(UIColor *)endColor directionType:(WHGradientDirection)directionType option:(CGSize)size;
85 |
86 | // Radial Gradient
87 | + (UIImage *)getRadialGradientImage:(UIColor *)centerColor and:(UIColor *)outColor;/* raduis = kDefaultWidth / 2 */
88 | + (UIImage *)getRadialGradientImage:(UIColor *)centerColor and:(UIColor *)outColor option:(CGSize)size;
89 |
90 | // ChromatoAnimation
91 | + (void)addGradientChromatoAnimation:(UIView *)view;
92 |
93 |
94 | // LableText LinearGradient and ChromatoAnimation
95 | + (void)addLinearGradientForLableText:(UIView *)parentView lable:(UILabel *)lable start:(UIColor *)startColor and:(UIColor *)endColor; /* don't need call 'addSubview:' for lable */
96 | + (void)addGradientChromatoAnimationForLableText:(UIView *)parentView lable:(UILabel *)lable; /* don't need call 'addSubview:' for lable */
97 | ```
98 |
99 | ## 具体实现
100 | [简书地址](https://www.jianshu.com/p/1045575db4d0)
101 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/xcuserdata/Balzac.xcuserdatad/xcschemes/Example.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/View+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | /**
14 | * Provides constraint maker block
15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs
16 | */
17 | @interface MAS_VIEW (MASAdditions)
18 |
19 | /**
20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
21 | */
22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);
34 |
35 | #if TARGET_OS_IPHONE
36 |
37 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin;
38 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin;
39 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin;
40 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin;
41 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin;
42 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin;
43 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;
45 |
46 | #endif
47 |
48 | /**
49 | * a key to associate with this view
50 | */
51 | @property (nonatomic, strong) id mas_key;
52 |
53 | /**
54 | * Finds the closest common superview between this view and another view
55 | *
56 | * @param view other view
57 | *
58 | * @return returns nil if common superview could not be found
59 | */
60 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
61 |
62 | /**
63 | * Creates a MASConstraintMaker with the callee view.
64 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
65 | *
66 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
67 | *
68 | * @return Array of created MASConstraints
69 | */
70 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
71 |
72 | /**
73 | * Creates a MASConstraintMaker with the callee view.
74 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
75 | * If an existing constraint exists then it will be updated instead.
76 | *
77 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
78 | *
79 | * @return Array of created/updated MASConstraints
80 | */
81 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
82 |
83 | /**
84 | * Creates a MASConstraintMaker with the callee view.
85 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
86 | * All constraints previously installed for the view will be removed.
87 | *
88 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
89 | *
90 | * @return Array of created/updated MASConstraints
91 | */
92 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
93 |
94 | @end
95 |
--------------------------------------------------------------------------------
/Example/Example/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "WHGradientHelper.h"
11 | #import "Globals.h"
12 | #import "Masonry.h"
13 | #import "MoreViewController.h"
14 |
15 | @interface ViewController ()
16 |
17 |
18 | @end
19 |
20 | @implementation ViewController
21 |
22 | - (void)viewDidLoad {
23 | [super viewDidLoad];
24 | self.view.backgroundColor = [UIColor whiteColor];
25 |
26 | //navigation
27 | [self.navigationController.navigationBar setBackgroundImage:[WHGradientHelper getLinearGradientImage:kColor1 and:kColor2 directionType:WHLinearGradientDirectionLevel option:CGSizeMake(375, 64)] forBarMetrics:UIBarMetricsDefault];
28 |
29 | // Linear Gradient
30 |
31 | UIImageView *image000 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 40, 200, 44)];
32 | image000.layer.masksToBounds = YES;
33 | image000.layer.cornerRadius = 22;
34 | image000.image = [WHGradientHelper getLinearGradientImage:kColor3 and:kColor4 directionType:WHLinearGradientDirectionLevel];
35 | [self.view addSubview:image000];
36 |
37 | UIImageView *image111 = [[UIImageView alloc] initWithFrame:CGRectMake(300, 40, 44, 200)];
38 | image111.layer.masksToBounds = YES;
39 | image111.layer.cornerRadius = 22;
40 | image111.image = [WHGradientHelper getLinearGradientImage:kColor5 and:kColor6 directionType:WHLinearGradientDirectionVertical];
41 | [self.view addSubview:image111];
42 |
43 | UIImageView *image222 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 100, 200, 100)];
44 | image222.image = [WHGradientHelper getLinearGradientImage:kColor7 and:kColor8 directionType:WHLinearGradientDirectionUpwardDiagonalLine];
45 | [self.view addSubview:image222];
46 |
47 | UIImageView *image333 = [[UIImageView alloc] initWithFrame:CGRectMake(30, 240, 200, 100)];
48 | image333.image = [WHGradientHelper getLinearGradientImage:[UIColor blackColor] and:[UIColor whiteColor] directionType:WHLinearGradientDirectionDownDiagonalLine];
49 | [self.view addSubview:image333];
50 |
51 | // Radial Gradient
52 | UIImageView *imgViewLeft = [[UIImageView alloc] initWithFrame:CGRectMake(60, 440, 80, 80)];
53 | imgViewLeft.image = [WHGradientHelper getRadialGradientImage:kColor1 and:kColor2];
54 | [self.view addSubview:imgViewLeft];
55 |
56 | UIImageView *imgViewRight = [[UIImageView alloc] initWithFrame:CGRectMake(235, 440, 80, 80)];
57 | imgViewRight.image = [WHGradientHelper getRadialGradientImage:kColor1 and:kColor2];
58 | [self.view addSubview:imgViewRight];
59 |
60 | UIImageView *imgViewMiddle = [[UIImageView alloc] initWithFrame:CGRectMake(180, 510, 15, 15)];
61 | imgViewMiddle.image = [WHGradientHelper getRadialGradientImage:kColor1 and:kColor2];
62 | [self.view addSubview:imgViewMiddle];
63 |
64 |
65 | // ChromatoAnimation
66 | UIImageView *imageView2 = [[UIImageView alloc] init];
67 | imageView2.layer.masksToBounds = YES;
68 | imageView2.layer.cornerRadius = 22;
69 |
70 | [self.view addSubview:imageView2];
71 | [imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
72 | make.left.mas_equalTo(self.view.mas_left).offset(50);
73 | make.centerX.mas_equalTo(self.view);
74 | make.height.mas_equalTo(44);
75 | make.bottom.mas_equalTo(self.view.mas_bottom).offset(-30);
76 | }];
77 |
78 | [self.view setNeedsLayout];
79 | [self.view layoutIfNeeded];
80 |
81 | [WHGradientHelper addGradientChromatoAnimation:imageView2];
82 |
83 |
84 | //more
85 | UIButton *moreBtn = [[UIButton alloc] initWithFrame:CGRectMake(300, 320, 64, 64)];
86 | [moreBtn setTitle:@"More" forState:UIControlStateNormal];
87 | [moreBtn setBackgroundImage:[WHGradientHelper getRadialGradientImage:kColor1 and:kColor2] forState:UIControlStateNormal];
88 | [moreBtn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
89 | [self.view addSubview:moreBtn];
90 |
91 | }
92 |
93 | #pragma mark - buttonAction
94 | - (void)btnAction
95 | {
96 | MoreViewController *moreVC =[[MoreViewController alloc] init];
97 |
98 | [self presentViewController:moreVC animated:YES completion:nil];
99 | }
100 |
101 |
102 |
103 | @end
104 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/View+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand view additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface MAS_VIEW (MASShorthandAdditions)
18 |
19 | @property (nonatomic, strong, readonly) MASViewAttribute *left;
20 | @property (nonatomic, strong, readonly) MASViewAttribute *top;
21 | @property (nonatomic, strong, readonly) MASViewAttribute *right;
22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *width;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *height;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
31 |
32 | #if TARGET_OS_IPHONE
33 |
34 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
35 | @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
36 | @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
37 | @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
38 | @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
39 | @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
40 | @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
41 | @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
42 |
43 | #endif
44 |
45 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
46 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
47 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
48 |
49 | @end
50 |
51 | #ifndef PINSSIBLE_OBFUSCATE_ENABLE
52 |
53 | #define pins_mas_top mas_top
54 | #define pins_mas_left mas_left
55 | #define pins_mas_bottom mas_bottom
56 | #define pins_mas_right mas_right
57 | #define pins_mas_leading mas_leading
58 | #define pins_mas_trailing mas_trailing
59 | #define pins_mas_width mas_width
60 | #define pins_mas_height mas_height
61 | #define pins_mas_centerX mas_centerX
62 | #define pins_mas_centerY mas_centerY
63 | #define pins_mas_baseline mas_baseline
64 | #define pins_mas_leftMargin mas_leftMargin
65 | #define pins_mas_rightMargin mas_rightMargin
66 | #define pins_mas_topMargin mas_topMargin
67 | #define pins_mas_bottomMargin mas_bottomMargin
68 | #define pins_mas_leadingMargin mas_leadingMargin
69 | #define pins_mas_trailingMargin mas_trailingMargin
70 | #define pins_mas_centerXWithinMargins mas_centerXWithinMargins
71 | #define pins_mas_centerYWithinMargins mas_centerYWithinMargins
72 |
73 | #endif
74 |
75 | #define MAS_ATTR_FORWARD(attr) \
76 | - (MASViewAttribute *)attr { \
77 | return [self pins_mas_##attr]; \
78 | }
79 |
80 | @implementation MAS_VIEW (MASShorthandAdditions)
81 |
82 | MAS_ATTR_FORWARD(top);
83 | MAS_ATTR_FORWARD(left);
84 | MAS_ATTR_FORWARD(bottom);
85 | MAS_ATTR_FORWARD(right);
86 | MAS_ATTR_FORWARD(leading);
87 | MAS_ATTR_FORWARD(trailing);
88 | MAS_ATTR_FORWARD(width);
89 | MAS_ATTR_FORWARD(height);
90 | MAS_ATTR_FORWARD(centerX);
91 | MAS_ATTR_FORWARD(centerY);
92 | MAS_ATTR_FORWARD(baseline);
93 |
94 | #if TARGET_OS_IPHONE
95 |
96 | MAS_ATTR_FORWARD(leftMargin);
97 | MAS_ATTR_FORWARD(rightMargin);
98 | MAS_ATTR_FORWARD(topMargin);
99 | MAS_ATTR_FORWARD(bottomMargin);
100 | MAS_ATTR_FORWARD(leadingMargin);
101 | MAS_ATTR_FORWARD(trailingMargin);
102 | MAS_ATTR_FORWARD(centerXWithinMargins);
103 | MAS_ATTR_FORWARD(centerYWithinMargins);
104 |
105 | #endif
106 |
107 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
108 | return [self mas_attribute];
109 | }
110 |
111 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
112 | return [self mas_makeConstraints:block];
113 | }
114 |
115 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
116 | return [self mas_updateConstraints:block];
117 | }
118 |
119 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
120 | return [self mas_remakeConstraints:block];
121 | }
122 |
123 | @end
124 |
125 | #endif
126 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASCompositeConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASCompositeConstraint.h"
10 | #import "MASConstraint+Private.h"
11 |
12 | @interface MASCompositeConstraint ()
13 |
14 | @property (nonatomic, strong) id mas_key;
15 | @property (nonatomic, strong) NSMutableArray *childConstraints;
16 |
17 | @end
18 |
19 | @implementation MASCompositeConstraint
20 |
21 | - (id)initWithChildren:(NSArray *)children {
22 | self = [super init];
23 | if (!self) return nil;
24 |
25 | _childConstraints = [children mutableCopy];
26 | for (MASConstraint *constraint in _childConstraints) {
27 | constraint.delegate = self;
28 | }
29 |
30 | return self;
31 | }
32 |
33 | #pragma mark - MASConstraintDelegate
34 |
35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
36 | NSUInteger index = [self.childConstraints indexOfObject:constraint];
37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint];
39 | }
40 |
41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
42 | id strongDelegate = self.delegate;
43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
44 | newConstraint.delegate = self;
45 | [self.childConstraints addObject:newConstraint];
46 | return newConstraint;
47 | }
48 |
49 | #pragma mark - NSLayoutConstraint multiplier proxies
50 |
51 | - (MASConstraint * (^)(CGFloat))multipliedBy {
52 | return ^id(CGFloat multiplier) {
53 | for (MASConstraint *constraint in self.childConstraints) {
54 | constraint.multipliedBy(multiplier);
55 | }
56 | return self;
57 | };
58 | }
59 |
60 | - (MASConstraint * (^)(CGFloat))dividedBy {
61 | return ^id(CGFloat divider) {
62 | for (MASConstraint *constraint in self.childConstraints) {
63 | constraint.dividedBy(divider);
64 | }
65 | return self;
66 | };
67 | }
68 |
69 | #pragma mark - MASLayoutPriority proxy
70 |
71 | - (MASConstraint * (^)(MASLayoutPriority))priority {
72 | return ^id(MASLayoutPriority priority) {
73 | for (MASConstraint *constraint in self.childConstraints) {
74 | constraint.priority(priority);
75 | }
76 | return self;
77 | };
78 | }
79 |
80 | #pragma mark - NSLayoutRelation proxy
81 |
82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
83 | return ^id(id attr, NSLayoutRelation relation) {
84 | for (MASConstraint *constraint in self.childConstraints.copy) {
85 | constraint.equalToWithRelation(attr, relation);
86 | }
87 | return self;
88 | };
89 | }
90 |
91 | #pragma mark - attribute chaining
92 |
93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
95 | return self;
96 | }
97 |
98 | #pragma mark - Animator proxy
99 |
100 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
101 |
102 | - (MASConstraint *)animator {
103 | for (MASConstraint *constraint in self.childConstraints) {
104 | [constraint animator];
105 | }
106 | return self;
107 | }
108 |
109 | #endif
110 |
111 | #pragma mark - debug helpers
112 |
113 | - (MASConstraint * (^)(id))key {
114 | return ^id(id key) {
115 | self.mas_key = key;
116 | int i = 0;
117 | for (MASConstraint *constraint in self.childConstraints) {
118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]);
119 | }
120 | return self;
121 | };
122 | }
123 |
124 | #pragma mark - NSLayoutConstraint constant setters
125 |
126 | - (void)setInsets:(MASEdgeInsets)insets {
127 | for (MASConstraint *constraint in self.childConstraints) {
128 | [constraint setInsets:insets];
129 | }
130 | }
131 |
132 | - (void)setOffset:(CGFloat)offset {
133 | for (MASConstraint *constraint in self.childConstraints) {
134 | [constraint setOffset:offset];
135 | }
136 | }
137 |
138 | - (void)setSizeOffset:(CGSize)sizeOffset {
139 | for (MASConstraint *constraint in self.childConstraints) {
140 | [constraint setSizeOffset:sizeOffset];
141 | }
142 | }
143 |
144 | - (void)setCenterOffset:(CGPoint)centerOffset {
145 | for (MASConstraint *constraint in self.childConstraints) {
146 | [constraint setCenterOffset:centerOffset];
147 | }
148 | }
149 |
150 | #pragma mark - MASConstraint
151 |
152 | - (void)activate {
153 | for (MASConstraint *constraint in self.childConstraints) {
154 | [constraint activate];
155 | }
156 | }
157 |
158 | - (void)deactivate {
159 | for (MASConstraint *constraint in self.childConstraints) {
160 | [constraint deactivate];
161 | }
162 | }
163 |
164 | - (void)install {
165 | for (MASConstraint *constraint in self.childConstraints) {
166 | constraint.updateExisting = self.updateExisting;
167 | [constraint install];
168 | }
169 | }
170 |
171 | - (void)uninstall {
172 | for (MASConstraint *constraint in self.childConstraints) {
173 | [constraint uninstall];
174 | }
175 | }
176 |
177 | @end
178 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASConstraintMaker.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintBuilder.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | typedef NS_OPTIONS(NSInteger, MASAttribute) {
13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft,
14 | MASAttributeRight = 1 << NSLayoutAttributeRight,
15 | MASAttributeTop = 1 << NSLayoutAttributeTop,
16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom,
17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading,
18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth,
20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight,
21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
24 |
25 | #if TARGET_OS_IPHONE
26 |
27 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
28 | MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
29 | MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
30 | MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
31 | MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
32 | MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
33 | MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
34 | MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,
35 |
36 | #endif
37 |
38 | };
39 |
40 | /**
41 | * Provides factory methods for creating MASConstraints.
42 | * Constraints are collected until they are ready to be installed
43 | *
44 | */
45 | @interface MASConstraintMaker : NSObject
46 |
47 | /**
48 | * The following properties return a new MASViewConstraint
49 | * with the first item set to the makers associated view and the appropriate MASViewAttribute
50 | */
51 | @property (nonatomic, strong, readonly) MASConstraint *left;
52 | @property (nonatomic, strong, readonly) MASConstraint *top;
53 | @property (nonatomic, strong, readonly) MASConstraint *right;
54 | @property (nonatomic, strong, readonly) MASConstraint *bottom;
55 | @property (nonatomic, strong, readonly) MASConstraint *leading;
56 | @property (nonatomic, strong, readonly) MASConstraint *trailing;
57 | @property (nonatomic, strong, readonly) MASConstraint *width;
58 | @property (nonatomic, strong, readonly) MASConstraint *height;
59 | @property (nonatomic, strong, readonly) MASConstraint *centerX;
60 | @property (nonatomic, strong, readonly) MASConstraint *centerY;
61 | @property (nonatomic, strong, readonly) MASConstraint *baseline;
62 |
63 | #if TARGET_OS_IPHONE
64 |
65 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin;
66 | @property (nonatomic, strong, readonly) MASConstraint *rightMargin;
67 | @property (nonatomic, strong, readonly) MASConstraint *topMargin;
68 | @property (nonatomic, strong, readonly) MASConstraint *bottomMargin;
69 | @property (nonatomic, strong, readonly) MASConstraint *leadingMargin;
70 | @property (nonatomic, strong, readonly) MASConstraint *trailingMargin;
71 | @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins;
72 | @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins;
73 |
74 | #endif
75 |
76 | /**
77 | * Returns a block which creates a new MASCompositeConstraint with the first item set
78 | * to the makers associated view and children corresponding to the set bits in the
79 | * MASAttribute parameter. Combine multiple attributes via binary-or.
80 | */
81 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs);
82 |
83 | /**
84 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
85 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
86 | * with the first item set to the makers associated view
87 | */
88 | @property (nonatomic, strong, readonly) MASConstraint *edges;
89 |
90 | /**
91 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
92 | * which generates the appropriate MASViewConstraint children (width, height)
93 | * with the first item set to the makers associated view
94 | */
95 | @property (nonatomic, strong, readonly) MASConstraint *size;
96 |
97 | /**
98 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
99 | * which generates the appropriate MASViewConstraint children (centerX, centerY)
100 | * with the first item set to the makers associated view
101 | */
102 | @property (nonatomic, strong, readonly) MASConstraint *center;
103 |
104 | /**
105 | * Whether or not to check for an existing constraint instead of adding constraint
106 | */
107 | @property (nonatomic, assign) BOOL updateExisting;
108 |
109 | /**
110 | * Whether or not to remove existing constraints prior to installing
111 | */
112 | @property (nonatomic, assign) BOOL removeExisting;
113 |
114 | /**
115 | * initialises the maker with a default view
116 | *
117 | * @param view any MASConstrait are created with this view as the first item
118 | *
119 | * @return a new MASConstraintMaker
120 | */
121 | - (id)initWithView:(MAS_VIEW *)view;
122 |
123 | /**
124 | * Calls install method on any MASConstraints which have been created by this maker
125 | *
126 | * @return an array of all the installed MASConstraints
127 | */
128 | - (NSArray *)install;
129 |
130 | - (MASConstraint * (^)(dispatch_block_t))group;
131 |
132 | @end
133 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/View+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 | #import
11 |
12 | @implementation MAS_VIEW (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block {
15 | self.translatesAutoresizingMaskIntoConstraints = NO;
16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
17 | block(constraintMaker);
18 | return [constraintMaker install];
19 | }
20 |
21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block {
22 | self.translatesAutoresizingMaskIntoConstraints = NO;
23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
24 | constraintMaker.updateExisting = YES;
25 | block(constraintMaker);
26 | return [constraintMaker install];
27 | }
28 |
29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
30 | self.translatesAutoresizingMaskIntoConstraints = NO;
31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
32 | constraintMaker.removeExisting = YES;
33 | block(constraintMaker);
34 | return [constraintMaker install];
35 | }
36 |
37 | #pragma mark - NSLayoutAttribute properties
38 |
39 | - (MASViewAttribute *)mas_left {
40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft];
41 | }
42 |
43 | - (MASViewAttribute *)mas_top {
44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop];
45 | }
46 |
47 | - (MASViewAttribute *)mas_right {
48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight];
49 | }
50 |
51 | - (MASViewAttribute *)mas_bottom {
52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom];
53 | }
54 |
55 | - (MASViewAttribute *)mas_leading {
56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading];
57 | }
58 |
59 | - (MASViewAttribute *)mas_trailing {
60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing];
61 | }
62 |
63 | - (MASViewAttribute *)mas_width {
64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth];
65 | }
66 |
67 | - (MASViewAttribute *)mas_height {
68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight];
69 | }
70 |
71 | - (MASViewAttribute *)mas_centerX {
72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX];
73 | }
74 |
75 | - (MASViewAttribute *)mas_centerY {
76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY];
77 | }
78 |
79 | - (MASViewAttribute *)mas_baseline {
80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline];
81 | }
82 |
83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute
84 | {
85 | return ^(NSLayoutAttribute attr) {
86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr];
87 | };
88 | }
89 |
90 | #if TARGET_OS_IPHONE
91 |
92 | - (MASViewAttribute *)mas_leftMargin {
93 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin];
94 | }
95 |
96 | - (MASViewAttribute *)mas_rightMargin {
97 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin];
98 | }
99 |
100 | - (MASViewAttribute *)mas_topMargin {
101 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin];
102 | }
103 |
104 | - (MASViewAttribute *)mas_bottomMargin {
105 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin];
106 | }
107 |
108 | - (MASViewAttribute *)mas_leadingMargin {
109 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin];
110 | }
111 |
112 | - (MASViewAttribute *)mas_trailingMargin {
113 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin];
114 | }
115 |
116 | - (MASViewAttribute *)mas_centerXWithinMargins {
117 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins];
118 | }
119 |
120 | - (MASViewAttribute *)mas_centerYWithinMargins {
121 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins];
122 | }
123 |
124 | #endif
125 |
126 | #pragma mark - associated properties
127 |
128 | - (id)mas_key {
129 | return objc_getAssociatedObject(self, @selector(mas_key));
130 | }
131 |
132 | - (void)setMas_key:(id)key {
133 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
134 | }
135 |
136 | #pragma mark - heirachy
137 |
138 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view {
139 | MAS_VIEW *closestCommonSuperview = nil;
140 |
141 | MAS_VIEW *secondViewSuperview = view;
142 | while (!closestCommonSuperview && secondViewSuperview) {
143 | MAS_VIEW *firstViewSuperview = self;
144 | while (!closestCommonSuperview && firstViewSuperview) {
145 | if (secondViewSuperview == firstViewSuperview) {
146 | closestCommonSuperview = secondViewSuperview;
147 | }
148 | firstViewSuperview = firstViewSuperview.superview;
149 | }
150 | secondViewSuperview = secondViewSuperview.superview;
151 | }
152 | return closestCommonSuperview;
153 | }
154 |
155 | @end
156 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/NSLayoutConstraint+MASDebugAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSLayoutConstraint+MASDebugAdditions.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 |
13 | @implementation NSLayoutConstraint (MASDebugAdditions)
14 |
15 | #pragma mark - description maps
16 |
17 | + (NSDictionary *)layoutRelationDescriptionsByValue {
18 | static dispatch_once_t once;
19 | static NSDictionary *descriptionMap;
20 | dispatch_once(&once, ^{
21 | descriptionMap = @{
22 | @(NSLayoutRelationEqual) : @"==",
23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=",
24 | @(NSLayoutRelationLessThanOrEqual) : @"<=",
25 | };
26 | });
27 | return descriptionMap;
28 | }
29 |
30 | + (NSDictionary *)layoutAttributeDescriptionsByValue {
31 | static dispatch_once_t once;
32 | static NSDictionary *descriptionMap;
33 | dispatch_once(&once, ^{
34 | descriptionMap = @{
35 | @(NSLayoutAttributeTop) : @"top",
36 | @(NSLayoutAttributeLeft) : @"left",
37 | @(NSLayoutAttributeBottom) : @"bottom",
38 | @(NSLayoutAttributeRight) : @"right",
39 | @(NSLayoutAttributeLeading) : @"leading",
40 | @(NSLayoutAttributeTrailing) : @"trailing",
41 | @(NSLayoutAttributeWidth) : @"width",
42 | @(NSLayoutAttributeHeight) : @"height",
43 | @(NSLayoutAttributeCenterX) : @"centerX",
44 | @(NSLayoutAttributeCenterY) : @"centerY",
45 | @(NSLayoutAttributeBaseline) : @"baseline",
46 |
47 | #if TARGET_OS_IPHONE
48 | @(NSLayoutAttributeLeftMargin) : @"leftMargin",
49 | @(NSLayoutAttributeRightMargin) : @"rightMargin",
50 | @(NSLayoutAttributeTopMargin) : @"topMargin",
51 | @(NSLayoutAttributeBottomMargin) : @"bottomMargin",
52 | @(NSLayoutAttributeLeadingMargin) : @"leadingMargin",
53 | @(NSLayoutAttributeTrailingMargin) : @"trailingMargin",
54 | @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins",
55 | @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins",
56 | #endif
57 |
58 | };
59 |
60 | });
61 | return descriptionMap;
62 | }
63 |
64 |
65 | + (NSDictionary *)layoutPriorityDescriptionsByValue {
66 | static dispatch_once_t once;
67 | static NSDictionary *descriptionMap;
68 | dispatch_once(&once, ^{
69 | #if TARGET_OS_IPHONE
70 | descriptionMap = @{
71 | @(MASLayoutPriorityDefaultHigh) : @"high",
72 | @(MASLayoutPriorityDefaultLow) : @"low",
73 | @(MASLayoutPriorityDefaultMedium) : @"medium",
74 | @(MASLayoutPriorityRequired) : @"required",
75 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size",
76 | };
77 | #elif TARGET_OS_MAC
78 | descriptionMap = @{
79 | @(MASLayoutPriorityDefaultHigh) : @"high",
80 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window",
81 | @(MASLayoutPriorityDefaultMedium) : @"medium",
82 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put",
83 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window",
84 | @(MASLayoutPriorityDefaultLow) : @"low",
85 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size",
86 | @(MASLayoutPriorityRequired) : @"required",
87 | };
88 | #endif
89 | });
90 | return descriptionMap;
91 | }
92 |
93 | #pragma mark - description override
94 |
95 | + (NSString *)descriptionForObject:(id)obj {
96 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) {
97 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]];
98 | }
99 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
100 | }
101 |
102 | - (NSString *)description {
103 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"];
104 |
105 | [description appendString:[self.class descriptionForObject:self]];
106 |
107 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]];
108 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) {
109 | [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.firstAttribute)]];
110 | }
111 |
112 | [description appendFormat:@" %@", [self.class.layoutRelationDescriptionsByValue objectForKey:@(self.relation)]];
113 |
114 | if (self.secondItem) {
115 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]];
116 | }
117 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) {
118 | [description appendFormat:@".%@", [self.class.layoutAttributeDescriptionsByValue objectForKey:@(self.secondAttribute)]];
119 | }
120 |
121 | if (self.multiplier != 1) {
122 | [description appendFormat:@" * %g", self.multiplier];
123 | }
124 |
125 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) {
126 | [description appendFormat:@" %g", self.constant];
127 | } else {
128 | if (self.constant) {
129 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)];
130 | }
131 | }
132 |
133 | if (self.priority != MASLayoutPriorityRequired) {
134 | [description appendFormat:@" ^%@", [self.class.layoutPriorityDescriptionsByValue objectForKey:@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]];
135 | }
136 |
137 | [description appendString:@">"];
138 | return description;
139 | }
140 |
141 | @end
142 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASUtilities.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASUtilities.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 19/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | #if TARGET_OS_IPHONE
12 |
13 | #import
14 | #define MAS_VIEW UIView
15 | #define MAS_VIEW_CONTROLLER UIViewController
16 | #define MASEdgeInsets UIEdgeInsets
17 |
18 | typedef UILayoutPriority MASLayoutPriority;
19 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired;
20 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh;
21 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500;
22 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow;
23 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel;
24 |
25 | #elif TARGET_OS_MAC
26 |
27 | #import
28 | #define MAS_VIEW NSView
29 | #define MASEdgeInsets NSEdgeInsets
30 |
31 | typedef NSLayoutPriority MASLayoutPriority;
32 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired;
33 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh;
34 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow;
35 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501;
36 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut;
37 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow;
38 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow;
39 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression;
40 |
41 | #endif
42 |
43 | /**
44 | * Allows you to attach keys to objects matching the variable names passed.
45 | *
46 | * view1.mas_key = @"view1", view2.mas_key = @"view2";
47 | *
48 | * is equivalent to:
49 | *
50 | * MASAttachKeys(view1, view2);
51 | */
52 |
53 | #ifndef PINSSIBLE_OBFUSCATE_ENABLE
54 |
55 | #define pins_setMas_key setMas_key
56 |
57 | #endif
58 |
59 | #define MASAttachKeys(...) \
60 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
61 | for (id key in keyPairs.allKeys) { \
62 | id obj = keyPairs[key]; \
63 | NSAssert([obj respondsToSelector:@selector(pins_setMas_key:)], \
64 | @"Cannot attach mas_key to %@", obj); \
65 | [obj pins_setMas_key:key]; \
66 | }
67 |
68 | /**
69 | * Used to create object hashes
70 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html
71 | */
72 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger))
73 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch)))
74 |
75 | /**
76 | * Given a scalar or struct value, wraps it in NSValue
77 | * Based on EXPObjectify: https://github.com/specta/expecta
78 | */
79 | static inline id _MASBoxValue(const char *type, ...) {
80 | va_list v;
81 | va_start(v, type);
82 | id obj = nil;
83 | if (strcmp(type, @encode(id)) == 0) {
84 | id actual = va_arg(v, id);
85 | obj = actual;
86 | } else if (strcmp(type, @encode(CGPoint)) == 0) {
87 | CGPoint actual = (CGPoint)va_arg(v, CGPoint);
88 | obj = [NSValue value:&actual withObjCType:type];
89 | } else if (strcmp(type, @encode(CGSize)) == 0) {
90 | CGSize actual = (CGSize)va_arg(v, CGSize);
91 | obj = [NSValue value:&actual withObjCType:type];
92 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) {
93 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets);
94 | obj = [NSValue value:&actual withObjCType:type];
95 | } else if (strcmp(type, @encode(double)) == 0) {
96 | double actual = (double)va_arg(v, double);
97 | obj = [NSNumber numberWithDouble:actual];
98 | } else if (strcmp(type, @encode(float)) == 0) {
99 | float actual = (float)va_arg(v, double);
100 | obj = [NSNumber numberWithFloat:actual];
101 | } else if (strcmp(type, @encode(int)) == 0) {
102 | int actual = (int)va_arg(v, int);
103 | obj = [NSNumber numberWithInt:actual];
104 | } else if (strcmp(type, @encode(long)) == 0) {
105 | long actual = (long)va_arg(v, long);
106 | obj = [NSNumber numberWithLong:actual];
107 | } else if (strcmp(type, @encode(long long)) == 0) {
108 | long long actual = (long long)va_arg(v, long long);
109 | obj = [NSNumber numberWithLongLong:actual];
110 | } else if (strcmp(type, @encode(short)) == 0) {
111 | short actual = (short)va_arg(v, int);
112 | obj = [NSNumber numberWithShort:actual];
113 | } else if (strcmp(type, @encode(char)) == 0) {
114 | char actual = (char)va_arg(v, int);
115 | obj = [NSNumber numberWithChar:actual];
116 | } else if (strcmp(type, @encode(bool)) == 0) {
117 | bool actual = (bool)va_arg(v, int);
118 | obj = [NSNumber numberWithBool:actual];
119 | } else if (strcmp(type, @encode(unsigned char)) == 0) {
120 | unsigned char actual = (unsigned char)va_arg(v, unsigned int);
121 | obj = [NSNumber numberWithUnsignedChar:actual];
122 | } else if (strcmp(type, @encode(unsigned int)) == 0) {
123 | unsigned int actual = (unsigned int)va_arg(v, unsigned int);
124 | obj = [NSNumber numberWithUnsignedInt:actual];
125 | } else if (strcmp(type, @encode(unsigned long)) == 0) {
126 | unsigned long actual = (unsigned long)va_arg(v, unsigned long);
127 | obj = [NSNumber numberWithUnsignedLong:actual];
128 | } else if (strcmp(type, @encode(unsigned long long)) == 0) {
129 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long);
130 | obj = [NSNumber numberWithUnsignedLongLong:actual];
131 | } else if (strcmp(type, @encode(unsigned short)) == 0) {
132 | unsigned short actual = (unsigned short)va_arg(v, unsigned int);
133 | obj = [NSNumber numberWithUnsignedShort:actual];
134 | }
135 | va_end(v);
136 | return obj;
137 | }
138 |
139 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))
140 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * Enables Constraints to be created with chainable syntax
13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint)
14 | * or a group of NSLayoutConstraints (MASComposisteConstraint)
15 | */
16 | @interface MASConstraint : NSObject
17 |
18 | // Chaining Support
19 |
20 | /**
21 | * Modifies the NSLayoutConstraint constant,
22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
24 | */
25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets;
26 |
27 | /**
28 | * Modifies the NSLayoutConstraint constant,
29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
31 | */
32 | - (MASConstraint * (^)(CGSize offset))sizeOffset;
33 |
34 | /**
35 | * Modifies the NSLayoutConstraint constant,
36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
38 | */
39 | - (MASConstraint * (^)(CGPoint offset))centerOffset;
40 |
41 | /**
42 | * Modifies the NSLayoutConstraint constant
43 | */
44 | - (MASConstraint * (^)(CGFloat offset))offset;
45 |
46 | /**
47 | * Modifies the NSLayoutConstraint constant based on a value type
48 | */
49 | - (MASConstraint * (^)(NSValue *value))valueOffset;
50 |
51 | /**
52 | * Sets the NSLayoutConstraint multiplier property
53 | */
54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy;
55 |
56 | /**
57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy
58 | */
59 | - (MASConstraint * (^)(CGFloat divider))dividedBy;
60 |
61 | /**
62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
63 | */
64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority;
65 |
66 | /**
67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
68 | */
69 | - (MASConstraint * (^)())priorityLow;
70 |
71 | /**
72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
73 | */
74 | - (MASConstraint * (^)())priorityMedium;
75 |
76 | /**
77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
78 | */
79 | - (MASConstraint * (^)())priorityHigh;
80 |
81 | /**
82 | * Sets the constraint relation to NSLayoutRelationEqual
83 | * returns a block which accepts one of the following:
84 | * MASViewAttribute, UIView, NSValue, NSArray
85 | * see readme for more details.
86 | */
87 | - (MASConstraint * (^)(id attr))equalTo;
88 |
89 | /**
90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
91 | * returns a block which accepts one of the following:
92 | * MASViewAttribute, UIView, NSValue, NSArray
93 | * see readme for more details.
94 | */
95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo;
96 |
97 | /**
98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual
99 | * returns a block which accepts one of the following:
100 | * MASViewAttribute, UIView, NSValue, NSArray
101 | * see readme for more details.
102 | */
103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo;
104 |
105 | /**
106 | * Optional semantic property which has no effect but improves the readability of constraint
107 | */
108 | - (MASConstraint *)with;
109 |
110 | /**
111 | * Optional semantic property which has no effect but improves the readability of constraint
112 | */
113 | - (MASConstraint *)and;
114 |
115 | /**
116 | * Creates a new MASCompositeConstraint with the called attribute and reciever
117 | */
118 | - (MASConstraint *)left;
119 | - (MASConstraint *)top;
120 | - (MASConstraint *)right;
121 | - (MASConstraint *)bottom;
122 | - (MASConstraint *)leading;
123 | - (MASConstraint *)trailing;
124 | - (MASConstraint *)width;
125 | - (MASConstraint *)height;
126 | - (MASConstraint *)centerX;
127 | - (MASConstraint *)centerY;
128 | - (MASConstraint *)baseline;
129 |
130 | #if TARGET_OS_IPHONE
131 |
132 | - (MASConstraint *)leftMargin;
133 | - (MASConstraint *)rightMargin;
134 | - (MASConstraint *)topMargin;
135 | - (MASConstraint *)bottomMargin;
136 | - (MASConstraint *)leadingMargin;
137 | - (MASConstraint *)trailingMargin;
138 | - (MASConstraint *)centerXWithinMargins;
139 | - (MASConstraint *)centerYWithinMargins;
140 |
141 | #endif
142 |
143 |
144 | /**
145 | * Sets the constraint debug name
146 | */
147 | - (MASConstraint * (^)(id key))key;
148 |
149 | // NSLayoutConstraint constant Setters
150 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks
151 |
152 | /**
153 | * Modifies the NSLayoutConstraint constant,
154 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
155 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
156 | */
157 | - (void)setInsets:(MASEdgeInsets)insets;
158 |
159 | /**
160 | * Modifies the NSLayoutConstraint constant,
161 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
162 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
163 | */
164 | - (void)setSizeOffset:(CGSize)sizeOffset;
165 |
166 | /**
167 | * Modifies the NSLayoutConstraint constant,
168 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
169 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
170 | */
171 | - (void)setCenterOffset:(CGPoint)centerOffset;
172 |
173 | /**
174 | * Modifies the NSLayoutConstraint constant
175 | */
176 | - (void)setOffset:(CGFloat)offset;
177 |
178 |
179 | // NSLayoutConstraint Installation support
180 |
181 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
182 | /**
183 | * Whether or not to go through the animator proxy when modifying the constraint
184 | */
185 | @property (nonatomic, copy, readonly) MASConstraint *animator;
186 | #endif
187 |
188 | /**
189 | * Activates an NSLayoutConstraint if it's supported by an OS.
190 | * Invokes install otherwise.
191 | */
192 | - (void)activate;
193 |
194 | /**
195 | * Deactivates previously installed/activated NSLayoutConstraint.
196 | */
197 | - (void)deactivate;
198 |
199 | /**
200 | * Creates a NSLayoutConstraint and adds it to the appropriate view.
201 | */
202 | - (void)install;
203 |
204 | /**
205 | * Removes previously installed NSLayoutConstraint
206 | */
207 | - (void)uninstall;
208 |
209 | @end
210 |
211 |
212 | /**
213 | * Convenience auto-boxing macros for MASConstraint methods.
214 | *
215 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax.
216 | * A potential drawback of this is that the unprefixed macros will appear in global scope.
217 | */
218 |
219 | #ifndef PINSSIBLE_OBFUSCATE_ENABLE
220 |
221 | #define pins_equalTo equalTo
222 | #define pins_greaterThanOrEqualTo greaterThanOrEqualTo
223 | #define pins_lessThanOrEqualTo lessThanOrEqualTo
224 | #define pins_valueOffset valueOffset
225 |
226 | #endif
227 |
228 | #define mas_equalTo(...) pins_equalTo(MASBoxValue((__VA_ARGS__)))
229 | #define mas_greaterThanOrEqualTo(...) pins_greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
230 | #define mas_lessThanOrEqualTo(...) pins_lessThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
231 |
232 | #define mas_offset(...) pins_valueOffset(MASBoxValue((__VA_ARGS__)))
233 |
234 |
235 | #ifdef MAS_SHORTHAND_GLOBALS
236 |
237 | #define equalTo(...) mas_equalTo(__VA_ARGS__)
238 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__)
239 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__)
240 |
241 | #define offset(...) mas_offset(__VA_ARGS__)
242 |
243 | #endif
244 |
245 |
246 | @interface MASConstraint (AutoboxingSupport)
247 |
248 | /**
249 | * Aliases to corresponding relation methods (for shorthand macros)
250 | * Also needed to aid autocompletion
251 | */
252 | - (MASConstraint * (^)(id attr))mas_equalTo;
253 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo;
254 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo;
255 |
256 | /**
257 | * A dummy method to aid autocompletion
258 | */
259 | - (MASConstraint * (^)(id offset))mas_offset;
260 |
261 | @end
262 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 1/20/14.
6 | //
7 |
8 | #import "MASConstraint.h"
9 | #import "MASConstraint+Private.h"
10 |
11 | #define MASMethodNotImplemented() \
12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \
13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \
14 | userInfo:nil]
15 |
16 | @implementation MASConstraint
17 |
18 | #pragma mark - Init
19 |
20 | - (id)init {
21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly.");
22 | return [super init];
23 | }
24 |
25 | #pragma mark - NSLayoutRelation proxies
26 |
27 | - (MASConstraint * (^)(id))equalTo {
28 | return ^id(id attribute) {
29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
30 | };
31 | }
32 |
33 | - (MASConstraint * (^)(id))mas_equalTo {
34 | return ^id(id attribute) {
35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
36 | };
37 | }
38 |
39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo {
40 | return ^id(id attribute) {
41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
42 | };
43 | }
44 |
45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo {
46 | return ^id(id attribute) {
47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
48 | };
49 | }
50 |
51 | - (MASConstraint * (^)(id))lessThanOrEqualTo {
52 | return ^id(id attribute) {
53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
54 | };
55 | }
56 |
57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo {
58 | return ^id(id attribute) {
59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
60 | };
61 | }
62 |
63 | #pragma mark - MASLayoutPriority proxies
64 |
65 | - (MASConstraint * (^)())priorityLow {
66 | return ^id{
67 | self.priority(MASLayoutPriorityDefaultLow);
68 | return self;
69 | };
70 | }
71 |
72 | - (MASConstraint * (^)())priorityMedium {
73 | return ^id{
74 | self.priority(MASLayoutPriorityDefaultMedium);
75 | return self;
76 | };
77 | }
78 |
79 | - (MASConstraint * (^)())priorityHigh {
80 | return ^id{
81 | self.priority(MASLayoutPriorityDefaultHigh);
82 | return self;
83 | };
84 | }
85 |
86 | #pragma mark - NSLayoutConstraint constant proxies
87 |
88 | - (MASConstraint * (^)(MASEdgeInsets))insets {
89 | return ^id(MASEdgeInsets insets){
90 | [self setInsets:insets];
91 | return self;
92 | };
93 | }
94 |
95 | - (MASConstraint * (^)(CGSize))sizeOffset {
96 | return ^id(CGSize offset) {
97 | [self setSizeOffset:offset];
98 | return self;
99 | };
100 | }
101 |
102 | - (MASConstraint * (^)(CGPoint))centerOffset {
103 | return ^id(CGPoint offset) {
104 | [self setCenterOffset:offset];
105 | return self;
106 | };
107 | }
108 |
109 | - (MASConstraint * (^)(CGFloat))offset {
110 | return ^id(CGFloat offset){
111 | [self setOffset:offset];
112 | return self;
113 | };
114 | }
115 |
116 | - (MASConstraint * (^)(NSValue *value))valueOffset {
117 | return ^id(NSValue *offset) {
118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset);
119 | [self setLayoutConstantWithValue:offset];
120 | return self;
121 | };
122 | }
123 |
124 | - (MASConstraint * (^)(id offset))mas_offset {
125 | // Will never be called due to macro
126 | return nil;
127 | }
128 |
129 | #pragma mark - NSLayoutConstraint constant setter
130 |
131 | - (void)setLayoutConstantWithValue:(NSValue *)value {
132 | if ([value isKindOfClass:NSNumber.class]) {
133 | [self setOffset:[(NSNumber *)value doubleValue]];
134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) {
135 | CGPoint point;
136 | [value getValue:&point];
137 | [self setCenterOffset:point];
138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) {
139 | CGSize size;
140 | [value getValue:&size];
141 | [self setSizeOffset:size];
142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) {
143 | MASEdgeInsets insets;
144 | [value getValue:&insets];
145 | [self setInsets:insets];
146 | } else {
147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value);
148 | }
149 | }
150 |
151 | #pragma mark - Semantic properties
152 |
153 | - (MASConstraint *)with {
154 | return self;
155 | }
156 |
157 | - (MASConstraint *)and {
158 | return self;
159 | }
160 |
161 | #pragma mark - Chaining
162 |
163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute {
164 | MASMethodNotImplemented();
165 | }
166 |
167 | - (MASConstraint *)left {
168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
169 | }
170 |
171 | - (MASConstraint *)top {
172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
173 | }
174 |
175 | - (MASConstraint *)right {
176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
177 | }
178 |
179 | - (MASConstraint *)bottom {
180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
181 | }
182 |
183 | - (MASConstraint *)leading {
184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
185 | }
186 |
187 | - (MASConstraint *)trailing {
188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
189 | }
190 |
191 | - (MASConstraint *)width {
192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
193 | }
194 |
195 | - (MASConstraint *)height {
196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
197 | }
198 |
199 | - (MASConstraint *)centerX {
200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
201 | }
202 |
203 | - (MASConstraint *)centerY {
204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
205 | }
206 |
207 | - (MASConstraint *)baseline {
208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
209 | }
210 |
211 | #if TARGET_OS_IPHONE
212 |
213 | - (MASConstraint *)leftMargin {
214 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin];
215 | }
216 |
217 | - (MASConstraint *)rightMargin {
218 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin];
219 | }
220 |
221 | - (MASConstraint *)topMargin {
222 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin];
223 | }
224 |
225 | - (MASConstraint *)bottomMargin {
226 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin];
227 | }
228 |
229 | - (MASConstraint *)leadingMargin {
230 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin];
231 | }
232 |
233 | - (MASConstraint *)trailingMargin {
234 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin];
235 | }
236 |
237 | - (MASConstraint *)centerXWithinMargins {
238 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins];
239 | }
240 |
241 | - (MASConstraint *)centerYWithinMargins {
242 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins];
243 | }
244 |
245 | #endif
246 |
247 | #pragma mark - Abstract
248 |
249 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); }
250 |
251 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); }
252 |
253 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); }
254 |
255 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); }
256 |
257 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); }
258 |
259 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); }
260 |
261 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); }
262 |
263 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); }
264 |
265 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); }
266 |
267 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
268 |
269 | - (MASConstraint *)animator { MASMethodNotImplemented(); }
270 |
271 | #endif
272 |
273 | - (void)activate { MASMethodNotImplemented(); }
274 |
275 | - (void)deactivate { MASMethodNotImplemented(); }
276 |
277 | - (void)install { MASMethodNotImplemented(); }
278 |
279 | - (void)uninstall { MASMethodNotImplemented(); }
280 |
281 | @end
282 |
--------------------------------------------------------------------------------
/WHGradientHelper/WHGradientHelper.m:
--------------------------------------------------------------------------------
1 | //
2 | // WHGradientHelper.m
3 | // Example
4 | //
5 | // Created by whbalzac on 3/20/17.
6 | // Copyright © 2017 whbalzac. All rights reserved.
7 | //
8 |
9 | #import "WHGradientHelper.h"
10 |
11 | #define UIColorFromRGBA(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
12 | #define UIColorFronHSB(h,s,b) [UIColor colorWithHue:h saturation:s brightness:b alpha:1.0f]
13 |
14 |
15 | @implementation WHGradientHelper
16 |
17 | #pragma mark - Linear Gradient
18 |
19 | + (UIImage *)getLinearGradientImage:(UIColor *)startColor and:(UIColor *)endColor directionType:(WHGradientDirection)directionType
20 | {
21 | return [self getLinearGradientImage:startColor and:endColor directionType:directionType option:CGSizeMake(kDefaultWidth, kDefaultHeight)];
22 | }
23 |
24 |
25 | + (UIImage *)getLinearGradientImage:(UIColor *)startColor and:(UIColor *)endColor directionType:(WHGradientDirection)directionType option:(CGSize)size
26 | {
27 | CAGradientLayer *gradientLayer = [CAGradientLayer layer];
28 | gradientLayer.colors = @[(__bridge id)startColor.CGColor,
29 | (__bridge id)endColor.CGColor];
30 | gradientLayer.locations = @[@(0.0f), @(1.0f)];
31 |
32 | if (directionType == WHLinearGradientDirectionLevel) {
33 | gradientLayer.startPoint = CGPointMake(0, 0);
34 | gradientLayer.endPoint = CGPointMake(1, 0);
35 | }else if (directionType == WHLinearGradientDirectionVertical){
36 | gradientLayer.startPoint = CGPointMake(0, 0);
37 | gradientLayer.endPoint = CGPointMake(0, 1);
38 | }else if (directionType == WHLinearGradientDirectionUpwardDiagonalLine){
39 | gradientLayer.startPoint = CGPointMake(0, 0);
40 | gradientLayer.endPoint = CGPointMake(1, 1);
41 | }else if (directionType == WHLinearGradientDirectionDownDiagonalLine){
42 | gradientLayer.startPoint = CGPointMake(0, 1);
43 | gradientLayer.endPoint = CGPointMake(1, 0);
44 | }
45 |
46 | gradientLayer.frame = CGRectMake(0, 0, size.width, size.height);
47 | UIGraphicsBeginImageContextWithOptions(gradientLayer.frame.size, NO, 0);
48 | [gradientLayer renderInContext:UIGraphicsGetCurrentContext()];
49 | UIImage *gradientImage = UIGraphicsGetImageFromCurrentImageContext();
50 | UIGraphicsEndImageContext();
51 |
52 | return gradientImage;
53 | }
54 |
55 |
56 | #pragma mark - Radial Gradient
57 |
58 | + (UIImage *)getRadialGradientImage:(UIColor *)centerColor and:(UIColor *)outColor
59 | {
60 | return [self getRadialGradientImage:centerColor and:outColor option:CGSizeMake(kDefaultWidth, kDefaultWidth)];
61 | }
62 |
63 | + (UIImage *)getRadialGradientImage:(UIColor *)centerColor and:(UIColor *)outColor option:(CGSize)size
64 | {
65 | UIGraphicsBeginImageContext(size);
66 | CGContextRef gc = UIGraphicsGetCurrentContext();
67 |
68 | CGMutablePathRef path = CGPathCreateMutable();
69 | CGFloat raduis = MAX(size.width / 2, size.height / 2);
70 | CGPathAddArc(path, NULL, size.width / 2, size.height / 2, raduis, 0, 2 * M_PI, NO);
71 |
72 | [self drawRadialGradient:gc path:path startColor:centerColor.CGColor endColor:outColor.CGColor];
73 | CGPathRelease(path);
74 |
75 | UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
76 | UIGraphicsEndImageContext();
77 | return img;
78 | }
79 |
80 | + (void)drawRadialGradient:(CGContextRef)context
81 | path:(CGPathRef)path
82 | startColor:(CGColorRef)startColor
83 | endColor:(CGColorRef)endColor
84 | {
85 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
86 | CGFloat locations[] = { 0.0, 1.0 };
87 |
88 | NSArray *colors = @[(__bridge id) startColor, (__bridge id) endColor];
89 |
90 | CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);
91 |
92 |
93 | CGRect pathRect = CGPathGetBoundingBox(path);
94 | CGPoint center = CGPointMake(CGRectGetMidX(pathRect), CGRectGetMidY(pathRect));
95 | CGFloat radius = MAX(pathRect.size.width / 2.0, pathRect.size.height / 2.0) * sqrt(2);
96 |
97 | CGContextSaveGState(context);
98 | CGContextAddPath(context, path);
99 | CGContextEOClip(context);
100 |
101 | CGContextDrawRadialGradient(context, gradient, center, 0, center, radius, 0);
102 |
103 | CGContextRestoreGState(context);
104 |
105 | CGGradientRelease(gradient);
106 | CGColorSpaceRelease(colorSpace);
107 | }
108 |
109 | // ChromatoAnimation
110 | + (void)addGradientChromatoAnimation:(UIView *)view
111 | {
112 | if (view == nil) {
113 | return;
114 | }
115 |
116 | CGFloat btnHeight = view.bounds.size.height;;
117 | CGFloat btnWidth = view.bounds.size.width;
118 |
119 | CAGradientLayer *chromatoLayer = [CAGradientLayer layer];
120 | [chromatoLayer setColors:@[(__bridge id)UIColorFronHSB(0.63, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.75, 0.69, 0.88).CGColor]];
121 | [chromatoLayer setStartPoint:CGPointMake(0, 0)];
122 | [chromatoLayer setEndPoint:CGPointMake(1, 0)];
123 | chromatoLayer.locations = @[@(0.0f) ,@(1.0f)];
124 | [chromatoLayer setFrame:CGRectMake(0, 0, btnWidth, btnHeight)];
125 |
126 | CAKeyframeAnimation *chromateAnimate = [self createGradientChromatoKeyAnimation];
127 |
128 | [chromatoLayer addAnimation:chromateAnimate forKey:@"chromateAnimate"];
129 |
130 | if (chromatoLayer.superlayer == nil) {
131 | [view.layer insertSublayer:chromatoLayer below:view.layer.sublayers[0]];
132 | }
133 | }
134 |
135 | + (void)addLinearGradientForLableText:(UIView *)parentView lable:(UILabel *)lable start:(UIColor *)startColor and:(UIColor *)endColor;
136 | {
137 | if (parentView == nil || lable == nil) {
138 | return;
139 | }
140 |
141 | [parentView addSubview:lable];
142 |
143 | CAGradientLayer *chromatoLayer = [CAGradientLayer layer];
144 | [chromatoLayer setColors:@[(__bridge id)startColor.CGColor, (__bridge id)endColor.CGColor]];
145 | [chromatoLayer setStartPoint:CGPointMake(0, 0)];
146 | [chromatoLayer setEndPoint:CGPointMake(1, 0)];
147 | chromatoLayer.locations = @[@(0.0f) ,@(1.0f)];
148 | [chromatoLayer setFrame:parentView.frame];
149 |
150 | [parentView.layer addSublayer:chromatoLayer];
151 | chromatoLayer.mask = lable.layer;
152 | chromatoLayer.frame = chromatoLayer.bounds;
153 | }
154 |
155 | + (void)addGradientChromatoAnimationForLableText:(UIView *)parentView lable:(UILabel *)lable
156 | {
157 | if (parentView == nil || lable == nil) {
158 | return;
159 | }
160 |
161 | [parentView addSubview:lable];
162 |
163 | CAGradientLayer *chromatoLayer = [CAGradientLayer layer];
164 | [chromatoLayer setColors:@[(__bridge id)UIColorFronHSB(0.63, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.75, 0.69, 0.88).CGColor]];
165 | [chromatoLayer setStartPoint:CGPointMake(0, 0)];
166 | [chromatoLayer setEndPoint:CGPointMake(1, 0)];
167 | chromatoLayer.locations = @[@(0.0f) ,@(1.0f)];
168 | [chromatoLayer setFrame:parentView.frame];
169 |
170 | CAKeyframeAnimation *chromateAnimate = [self createGradientChromatoKeyAnimation];
171 |
172 | [chromatoLayer addAnimation:chromateAnimate forKey:@"chromateAnimate"];
173 |
174 | [parentView.layer addSublayer:chromatoLayer];
175 | chromatoLayer.mask = lable.layer;
176 | chromatoLayer.frame = chromatoLayer.bounds;
177 | }
178 |
179 |
180 | #pragma mark - private method
181 |
182 | + (CAKeyframeAnimation *)createGradientChromatoKeyAnimation
183 | {
184 | CAKeyframeAnimation *chromateAnimate = [CAKeyframeAnimation animationWithKeyPath:@"colors"];
185 |
186 | chromateAnimate.values = @[@[(__bridge id)UIColorFronHSB(0.63, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.75, 0.69, 0.88).CGColor],
187 | @[(__bridge id)UIColorFronHSB(0.73, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.85, 0.69, 0.88).CGColor],
188 | @[(__bridge id)UIColorFronHSB(0.83, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.95, 0.69, 0.88).CGColor],
189 | @[(__bridge id)UIColorFronHSB(0.88, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(1, 0.69, 0.88).CGColor],
190 | @[(__bridge id)UIColorFronHSB(0.98, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.1, 0.69, 0.88).CGColor],
191 | @[(__bridge id)UIColorFronHSB(1, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.12, 0.69, 0.88).CGColor],
192 | @[(__bridge id)UIColorFronHSB(0.1, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.22, 0.69, 0.88).CGColor],
193 | @[(__bridge id)UIColorFronHSB(0.2, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.32, 0.69, 0.88).CGColor],
194 | @[(__bridge id)UIColorFronHSB(0.3, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.42, 0.69, 0.88).CGColor],
195 | @[(__bridge id)UIColorFronHSB(0.4, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.52, 0.69, 0.88).CGColor],
196 | @[(__bridge id)UIColorFronHSB(0.5, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.62, 0.69, 0.88).CGColor],
197 | @[(__bridge id)UIColorFronHSB(0.6, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.72, 0.69, 0.88).CGColor],
198 | @[(__bridge id)UIColorFronHSB(0.63, 0.69, 0.88).CGColor, (__bridge id)UIColorFronHSB(0.75, 0.69, 0.88).CGColor]];
199 | chromateAnimate.keyTimes = @[@0, @0.1, @0.2, @0.25, @0.35, @0.37, @0.47, @0.57, @0.67, @0.77, @0.87, @0.97, @1];
200 | chromateAnimate.duration = 6;
201 | chromateAnimate.removedOnCompletion = NO;
202 | chromateAnimate.repeatCount = MAXFLOAT;
203 |
204 | return chromateAnimate;
205 | }
206 |
207 | @end
208 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASConstraintMaker.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintBuilder.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraintMaker.h"
10 | #import "MASViewConstraint.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASConstraint+Private.h"
13 | #import "MASViewAttribute.h"
14 | #import "View+MASAdditions.h"
15 |
16 | @interface MASConstraintMaker ()
17 |
18 | @property (nonatomic, weak) MAS_VIEW *view;
19 | @property (nonatomic, strong) NSMutableArray *constraints;
20 |
21 | @end
22 |
23 | @implementation MASConstraintMaker
24 |
25 | - (id)initWithView:(MAS_VIEW *)view {
26 | self = [super init];
27 | if (!self) return nil;
28 |
29 | self.view = view;
30 | self.constraints = NSMutableArray.new;
31 |
32 | return self;
33 | }
34 |
35 | - (NSArray *)install {
36 | if (self.removeExisting) {
37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view];
38 | for (MASConstraint *constraint in installedConstraints) {
39 | [constraint uninstall];
40 | }
41 | }
42 | NSArray *constraints = self.constraints.copy;
43 | for (MASConstraint *constraint in constraints) {
44 | constraint.updateExisting = self.updateExisting;
45 | [constraint install];
46 | }
47 | [self.constraints removeAllObjects];
48 | return constraints;
49 | }
50 |
51 | #pragma mark - MASConstraintDelegate
52 |
53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
54 | NSUInteger index = [self.constraints indexOfObject:constraint];
55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint];
57 | }
58 |
59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute];
61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
62 | if ([constraint isKindOfClass:MASViewConstraint.class]) {
63 | //replace with composite constraint
64 | NSArray *children = @[constraint, newConstraint];
65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
66 | compositeConstraint.delegate = self;
67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint];
68 | return compositeConstraint;
69 | }
70 | if (!constraint) {
71 | newConstraint.delegate = self;
72 | [self.constraints addObject:newConstraint];
73 | }
74 | return newConstraint;
75 | }
76 |
77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading
79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX
80 | | MASAttributeCenterY | MASAttributeBaseline
81 | #if TARGET_OS_IPHONE
82 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin
83 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins
84 | | MASAttributeCenterYWithinMargins
85 | #endif
86 | );
87 |
88 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");
89 |
90 | NSMutableArray *attributes = [NSMutableArray array];
91 |
92 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left];
93 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right];
94 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top];
95 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom];
96 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading];
97 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing];
98 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width];
99 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height];
100 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX];
101 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY];
102 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];
103 |
104 | #if TARGET_OS_IPHONE
105 |
106 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin];
107 | if (attrs & MASAttributeRightMargin) [attributes addObject:self.view.mas_rightMargin];
108 | if (attrs & MASAttributeTopMargin) [attributes addObject:self.view.mas_topMargin];
109 | if (attrs & MASAttributeBottomMargin) [attributes addObject:self.view.mas_bottomMargin];
110 | if (attrs & MASAttributeLeadingMargin) [attributes addObject:self.view.mas_leadingMargin];
111 | if (attrs & MASAttributeTrailingMargin) [attributes addObject:self.view.mas_trailingMargin];
112 | if (attrs & MASAttributeCenterXWithinMargins) [attributes addObject:self.view.mas_centerXWithinMargins];
113 | if (attrs & MASAttributeCenterYWithinMargins) [attributes addObject:self.view.mas_centerYWithinMargins];
114 |
115 | #endif
116 |
117 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count];
118 |
119 | for (MASViewAttribute *a in attributes) {
120 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]];
121 | }
122 |
123 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
124 | constraint.delegate = self;
125 | [self.constraints addObject:constraint];
126 | return constraint;
127 | }
128 |
129 | #pragma mark - standard Attributes
130 |
131 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
132 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute];
133 | }
134 |
135 | - (MASConstraint *)left {
136 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
137 | }
138 |
139 | - (MASConstraint *)top {
140 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
141 | }
142 |
143 | - (MASConstraint *)right {
144 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
145 | }
146 |
147 | - (MASConstraint *)bottom {
148 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
149 | }
150 |
151 | - (MASConstraint *)leading {
152 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
153 | }
154 |
155 | - (MASConstraint *)trailing {
156 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
157 | }
158 |
159 | - (MASConstraint *)width {
160 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
161 | }
162 |
163 | - (MASConstraint *)height {
164 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
165 | }
166 |
167 | - (MASConstraint *)centerX {
168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
169 | }
170 |
171 | - (MASConstraint *)centerY {
172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
173 | }
174 |
175 | - (MASConstraint *)baseline {
176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
177 | }
178 |
179 | - (MASConstraint *(^)(MASAttribute))attributes {
180 | return ^(MASAttribute attrs){
181 | return [self addConstraintWithAttributes:attrs];
182 | };
183 | }
184 |
185 | #if TARGET_OS_IPHONE
186 |
187 | - (MASConstraint *)leftMargin {
188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin];
189 | }
190 |
191 | - (MASConstraint *)rightMargin {
192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin];
193 | }
194 |
195 | - (MASConstraint *)topMargin {
196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin];
197 | }
198 |
199 | - (MASConstraint *)bottomMargin {
200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin];
201 | }
202 |
203 | - (MASConstraint *)leadingMargin {
204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin];
205 | }
206 |
207 | - (MASConstraint *)trailingMargin {
208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin];
209 | }
210 |
211 | - (MASConstraint *)centerXWithinMargins {
212 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins];
213 | }
214 |
215 | - (MASConstraint *)centerYWithinMargins {
216 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins];
217 | }
218 |
219 | #endif
220 |
221 |
222 | #pragma mark - composite Attributes
223 |
224 | - (MASConstraint *)edges {
225 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom];
226 | }
227 |
228 | - (MASConstraint *)size {
229 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight];
230 | }
231 |
232 | - (MASConstraint *)center {
233 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY];
234 | }
235 |
236 | #pragma mark - grouping
237 |
238 | - (MASConstraint *(^)(dispatch_block_t group))group {
239 | return ^id(dispatch_block_t group) {
240 | NSInteger previousCount = self.constraints.count;
241 | group();
242 |
243 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)];
244 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
245 | constraint.delegate = self;
246 | return constraint;
247 | };
248 | }
249 |
250 | @end
251 |
--------------------------------------------------------------------------------
/Example/Example/Masonry/MASViewConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewConstraint.h"
10 | #import "MASConstraint+Private.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASLayoutConstraint.h"
13 | #import "View+MASAdditions.h"
14 | #import
15 |
16 | @interface MAS_VIEW (MASConstraints)
17 |
18 | @property (nonatomic, readonly) NSMutableSet *mas_installedConstraints;
19 |
20 | @end
21 |
22 | @implementation MAS_VIEW (MASConstraints)
23 |
24 | static char kInstalledConstraintsKey;
25 |
26 | - (NSMutableSet *)mas_installedConstraints {
27 | NSMutableSet *constraints = objc_getAssociatedObject(self, &kInstalledConstraintsKey);
28 | if (!constraints) {
29 | constraints = [NSMutableSet set];
30 | objc_setAssociatedObject(self, &kInstalledConstraintsKey, constraints, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
31 | }
32 | return constraints;
33 | }
34 |
35 | @end
36 |
37 |
38 | @interface MASViewConstraint ()
39 |
40 | @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute;
41 | @property (nonatomic, weak) MAS_VIEW *installedView;
42 | @property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
43 | @property (nonatomic, assign) NSLayoutRelation layoutRelation;
44 | @property (nonatomic, assign) MASLayoutPriority layoutPriority;
45 | @property (nonatomic, assign) CGFloat layoutMultiplier;
46 | @property (nonatomic, assign) CGFloat layoutConstant;
47 | @property (nonatomic, assign) BOOL hasLayoutRelation;
48 | @property (nonatomic, strong) id mas_key;
49 | @property (nonatomic, assign) BOOL useAnimator;
50 |
51 | @end
52 |
53 | @implementation MASViewConstraint
54 |
55 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
56 | self = [super init];
57 | if (!self) return nil;
58 |
59 | _firstViewAttribute = firstViewAttribute;
60 | self.layoutPriority = MASLayoutPriorityRequired;
61 | self.layoutMultiplier = 1;
62 |
63 | return self;
64 | }
65 |
66 | #pragma mark - NSCoping
67 |
68 | - (id)copyWithZone:(NSZone __unused *)zone {
69 | MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:self.firstViewAttribute];
70 | constraint.layoutConstant = self.layoutConstant;
71 | constraint.layoutRelation = self.layoutRelation;
72 | constraint.layoutPriority = self.layoutPriority;
73 | constraint.layoutMultiplier = self.layoutMultiplier;
74 | constraint.delegate = self.delegate;
75 | return constraint;
76 | }
77 |
78 | #pragma mark - Public
79 |
80 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view {
81 | return [view.mas_installedConstraints allObjects];
82 | }
83 |
84 | #pragma mark - Private
85 |
86 | - (void)setLayoutConstant:(CGFloat)layoutConstant {
87 | _layoutConstant = layoutConstant;
88 |
89 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
90 | if (self.useAnimator) {
91 | [self.layoutConstraint.animator setConstant:layoutConstant];
92 | } else {
93 | self.layoutConstraint.constant = layoutConstant;
94 | }
95 | #else
96 | self.layoutConstraint.constant = layoutConstant;
97 | #endif
98 | }
99 |
100 | - (void)setLayoutRelation:(NSLayoutRelation)layoutRelation {
101 | _layoutRelation = layoutRelation;
102 | self.hasLayoutRelation = YES;
103 | }
104 |
105 | - (BOOL)supportsActiveProperty {
106 | return [self.layoutConstraint respondsToSelector:@selector(isActive)];
107 | }
108 |
109 | - (BOOL)isActive {
110 | BOOL active = YES;
111 | if ([self supportsActiveProperty]) {
112 | active = [self.layoutConstraint isActive];
113 | }
114 |
115 | return active;
116 | }
117 |
118 | - (BOOL)hasBeenInstalled {
119 | return (self.layoutConstraint != nil) && [self isActive];
120 | }
121 |
122 | - (void)setSecondViewAttribute:(id)secondViewAttribute {
123 | if ([secondViewAttribute isKindOfClass:NSValue.class]) {
124 | [self setLayoutConstantWithValue:secondViewAttribute];
125 | } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
126 | _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
127 | } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
128 | _secondViewAttribute = secondViewAttribute;
129 | } else {
130 | NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);
131 | }
132 | }
133 |
134 | #pragma mark - NSLayoutConstraint multiplier proxies
135 |
136 | - (MASConstraint * (^)(CGFloat))multipliedBy {
137 | return ^id(CGFloat multiplier) {
138 | NSAssert(!self.hasBeenInstalled,
139 | @"Cannot modify constraint multiplier after it has been installed");
140 |
141 | self.layoutMultiplier = multiplier;
142 | return self;
143 | };
144 | }
145 |
146 |
147 | - (MASConstraint * (^)(CGFloat))dividedBy {
148 | return ^id(CGFloat divider) {
149 | NSAssert(!self.hasBeenInstalled,
150 | @"Cannot modify constraint multiplier after it has been installed");
151 |
152 | self.layoutMultiplier = 1.0/divider;
153 | return self;
154 | };
155 | }
156 |
157 | #pragma mark - MASLayoutPriority proxy
158 |
159 | - (MASConstraint * (^)(MASLayoutPriority))priority {
160 | return ^id(MASLayoutPriority priority) {
161 | NSAssert(!self.hasBeenInstalled,
162 | @"Cannot modify constraint priority after it has been installed");
163 |
164 | self.layoutPriority = priority;
165 | return self;
166 | };
167 | }
168 |
169 | #pragma mark - NSLayoutRelation proxy
170 |
171 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
172 | return ^id(id attribute, NSLayoutRelation relation) {
173 | if ([attribute isKindOfClass:NSArray.class]) {
174 | NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation");
175 | NSMutableArray *children = NSMutableArray.new;
176 | for (id attr in attribute) {
177 | MASViewConstraint *viewConstraint = [self copy];
178 | viewConstraint.secondViewAttribute = attr;
179 | [children addObject:viewConstraint];
180 | }
181 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
182 | compositeConstraint.delegate = self.delegate;
183 | [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint];
184 | return compositeConstraint;
185 | } else {
186 | NSAssert(!self.hasLayoutRelation || self.layoutRelation == relation && [attribute isKindOfClass:NSValue.class], @"Redefinition of constraint relation");
187 | self.layoutRelation = relation;
188 | self.secondViewAttribute = attribute;
189 | return self;
190 | }
191 | };
192 | }
193 |
194 | #pragma mark - Semantic properties
195 |
196 | - (MASConstraint *)with {
197 | return self;
198 | }
199 |
200 | - (MASConstraint *)and {
201 | return self;
202 | }
203 |
204 | #pragma mark - attribute chaining
205 |
206 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
207 | NSAssert(!self.hasLayoutRelation, @"Attributes should be chained before defining the constraint relation");
208 |
209 | return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
210 | }
211 |
212 | #pragma mark - Animator proxy
213 |
214 | #if TARGET_OS_MAC && !TARGET_OS_IPHONE
215 |
216 | - (MASConstraint *)animator {
217 | self.useAnimator = YES;
218 | return self;
219 | }
220 |
221 | #endif
222 |
223 | #pragma mark - debug helpers
224 |
225 | - (MASConstraint * (^)(id))key {
226 | return ^id(id key) {
227 | self.mas_key = key;
228 | return self;
229 | };
230 | }
231 |
232 | #pragma mark - NSLayoutConstraint constant setters
233 |
234 | - (void)setInsets:(MASEdgeInsets)insets {
235 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
236 | switch (layoutAttribute) {
237 | case NSLayoutAttributeLeft:
238 | case NSLayoutAttributeLeading:
239 | self.layoutConstant = insets.left;
240 | break;
241 | case NSLayoutAttributeTop:
242 | self.layoutConstant = insets.top;
243 | break;
244 | case NSLayoutAttributeBottom:
245 | self.layoutConstant = -insets.bottom;
246 | break;
247 | case NSLayoutAttributeRight:
248 | case NSLayoutAttributeTrailing:
249 | self.layoutConstant = -insets.right;
250 | break;
251 | default:
252 | break;
253 | }
254 | }
255 |
256 | - (void)setOffset:(CGFloat)offset {
257 | self.layoutConstant = offset;
258 | }
259 |
260 | - (void)setSizeOffset:(CGSize)sizeOffset {
261 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
262 | switch (layoutAttribute) {
263 | case NSLayoutAttributeWidth:
264 | self.layoutConstant = sizeOffset.width;
265 | break;
266 | case NSLayoutAttributeHeight:
267 | self.layoutConstant = sizeOffset.height;
268 | break;
269 | default:
270 | break;
271 | }
272 | }
273 |
274 | - (void)setCenterOffset:(CGPoint)centerOffset {
275 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
276 | switch (layoutAttribute) {
277 | case NSLayoutAttributeCenterX:
278 | self.layoutConstant = centerOffset.x;
279 | break;
280 | case NSLayoutAttributeCenterY:
281 | self.layoutConstant = centerOffset.y;
282 | break;
283 | default:
284 | break;
285 | }
286 | }
287 |
288 | #pragma mark - MASConstraint
289 |
290 | - (void)activate {
291 | if ([self supportsActiveProperty] && self.layoutConstraint) {
292 | if (self.hasBeenInstalled) {
293 | return;
294 | }
295 | self.layoutConstraint.active = YES;
296 | [self.firstViewAttribute.view.mas_installedConstraints addObject:self];
297 | } else {
298 | [self install];
299 | }
300 | }
301 |
302 | - (void)deactivate {
303 | if ([self supportsActiveProperty]) {
304 | self.layoutConstraint.active = NO;
305 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
306 | } else {
307 | [self uninstall];
308 | }
309 | }
310 |
311 | - (void)install {
312 | if (self.hasBeenInstalled) {
313 | return;
314 | }
315 |
316 | MAS_VIEW *firstLayoutItem = self.firstViewAttribute.item;
317 | NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
318 | MAS_VIEW *secondLayoutItem = self.secondViewAttribute.item;
319 | NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute;
320 |
321 | // alignment attributes must have a secondViewAttribute
322 | // therefore we assume that is refering to superview
323 | // eg make.left.equalTo(@10)
324 | if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) {
325 | secondLayoutItem = self.firstViewAttribute.view.superview;
326 | secondLayoutAttribute = firstLayoutAttribute;
327 | }
328 |
329 | MASLayoutConstraint *layoutConstraint
330 | = [MASLayoutConstraint constraintWithItem:firstLayoutItem
331 | attribute:firstLayoutAttribute
332 | relatedBy:self.layoutRelation
333 | toItem:secondLayoutItem
334 | attribute:secondLayoutAttribute
335 | multiplier:self.layoutMultiplier
336 | constant:self.layoutConstant];
337 |
338 | layoutConstraint.priority = self.layoutPriority;
339 | layoutConstraint.mas_key = self.mas_key;
340 |
341 | if (self.secondViewAttribute.view) {
342 | MAS_VIEW *closestCommonSuperview = [self.firstViewAttribute.view mas_closestCommonSuperview:self.secondViewAttribute.view];
343 | NSAssert(closestCommonSuperview,
344 | @"couldn't find a common superview for %@ and %@",
345 | self.firstViewAttribute.view, self.secondViewAttribute.view);
346 | self.installedView = closestCommonSuperview;
347 | } else if (self.firstViewAttribute.isSizeAttribute) {
348 | self.installedView = self.firstViewAttribute.view;
349 | } else {
350 | self.installedView = self.firstViewAttribute.view.superview;
351 | }
352 |
353 |
354 | MASLayoutConstraint *existingConstraint = nil;
355 | if (self.updateExisting) {
356 | existingConstraint = [self layoutConstraintSimilarTo:layoutConstraint];
357 | }
358 | if (existingConstraint) {
359 | // just update the constant
360 | existingConstraint.constant = layoutConstraint.constant;
361 | self.layoutConstraint = existingConstraint;
362 | } else {
363 | [self.installedView addConstraint:layoutConstraint];
364 | self.layoutConstraint = layoutConstraint;
365 | [firstLayoutItem.mas_installedConstraints addObject:self];
366 | }
367 | }
368 |
369 | - (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layoutConstraint {
370 | // check if any constraints are the same apart from the only mutable property constant
371 |
372 | // go through constraints in reverse as we do not want to match auto-resizing or interface builder constraints
373 | // and they are likely to be added first.
374 | for (NSLayoutConstraint *existingConstraint in self.installedView.constraints.reverseObjectEnumerator) {
375 | if (![existingConstraint isKindOfClass:MASLayoutConstraint.class]) continue;
376 | if (existingConstraint.firstItem != layoutConstraint.firstItem) continue;
377 | if (existingConstraint.secondItem != layoutConstraint.secondItem) continue;
378 | if (existingConstraint.firstAttribute != layoutConstraint.firstAttribute) continue;
379 | if (existingConstraint.secondAttribute != layoutConstraint.secondAttribute) continue;
380 | if (existingConstraint.relation != layoutConstraint.relation) continue;
381 | if (existingConstraint.multiplier != layoutConstraint.multiplier) continue;
382 | if (existingConstraint.priority != layoutConstraint.priority) continue;
383 |
384 | return (id)existingConstraint;
385 | }
386 | return nil;
387 | }
388 |
389 | - (void)uninstall {
390 | [self.installedView removeConstraint:self.layoutConstraint];
391 | self.layoutConstraint = nil;
392 | self.installedView = nil;
393 |
394 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
395 | }
396 |
397 | @end
398 |
--------------------------------------------------------------------------------
/Example/Example.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | A52B76CB1E7FBA6500938AEA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = A52B76CA1E7FBA6500938AEA /* main.m */; };
11 | A52B76CE1E7FBA6500938AEA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = A52B76CD1E7FBA6500938AEA /* AppDelegate.m */; };
12 | A52B76D11E7FBA6500938AEA /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A52B76D01E7FBA6500938AEA /* ViewController.m */; };
13 | A52B76D41E7FBA6500938AEA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A52B76D21E7FBA6500938AEA /* Main.storyboard */; };
14 | A52B76D61E7FBA6500938AEA /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A52B76D51E7FBA6500938AEA /* Assets.xcassets */; };
15 | A52B76D91E7FBA6500938AEA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A52B76D71E7FBA6500938AEA /* LaunchScreen.storyboard */; };
16 | A52B76E31E7FBA8900938AEA /* WHGradientHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = A52B76E21E7FBA8900938AEA /* WHGradientHelper.m */; };
17 | A57B4F551E84244B008BCF2F /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = A57B4F3B1E84244B008BCF2F /* Info.plist */; };
18 | A57B4F561E84244B008BCF2F /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F3D1E84244B008BCF2F /* MASCompositeConstraint.m */; };
19 | A57B4F571E84244B008BCF2F /* MASConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F401E84244B008BCF2F /* MASConstraint.m */; };
20 | A57B4F581E84244B008BCF2F /* MASConstraintMaker.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F421E84244B008BCF2F /* MASConstraintMaker.m */; };
21 | A57B4F591E84244B008BCF2F /* MASLayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F441E84244B008BCF2F /* MASLayoutConstraint.m */; };
22 | A57B4F5A1E84244B008BCF2F /* MASViewAttribute.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F481E84244B008BCF2F /* MASViewAttribute.m */; };
23 | A57B4F5B1E84244B008BCF2F /* MASViewConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F4A1E84244B008BCF2F /* MASViewConstraint.m */; };
24 | A57B4F5C1E84244B008BCF2F /* NSArray+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F4C1E84244B008BCF2F /* NSArray+MASAdditions.m */; };
25 | A57B4F5D1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F4F1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.m */; };
26 | A57B4F5E1E84244B008BCF2F /* View+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F511E84244B008BCF2F /* View+MASAdditions.m */; };
27 | A57B4F5F1E84244B008BCF2F /* ViewController+MASAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A57B4F541E84244B008BCF2F /* ViewController+MASAdditions.m */; };
28 | A5F2884C1E88B5DB00193867 /* MoreViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A5F2884B1E88B5DB00193867 /* MoreViewController.m */; };
29 | A5F288501E88B61300193867 /* 11.png in Resources */ = {isa = PBXBuildFile; fileRef = A5F2884E1E88B61300193867 /* 11.png */; };
30 | A5F288511E88B61300193867 /* 22.png in Resources */ = {isa = PBXBuildFile; fileRef = A5F2884F1E88B61300193867 /* 22.png */; };
31 | /* End PBXBuildFile section */
32 |
33 | /* Begin PBXFileReference section */
34 | A52B76C61E7FBA6500938AEA /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
35 | A52B76CA1E7FBA6500938AEA /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; };
36 | A52B76CC1E7FBA6500938AEA /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; };
37 | A52B76CD1E7FBA6500938AEA /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; };
38 | A52B76CF1E7FBA6500938AEA /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; };
39 | A52B76D01E7FBA6500938AEA /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; };
40 | A52B76D31E7FBA6500938AEA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
41 | A52B76D51E7FBA6500938AEA /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
42 | A52B76D81E7FBA6500938AEA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
43 | A52B76DA1E7FBA6600938AEA /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
44 | A52B76E11E7FBA8900938AEA /* WHGradientHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WHGradientHelper.h; sourceTree = ""; };
45 | A52B76E21E7FBA8900938AEA /* WHGradientHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WHGradientHelper.m; sourceTree = ""; };
46 | A57B4F3B1E84244B008BCF2F /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
47 | A57B4F3C1E84244B008BCF2F /* MASCompositeConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASCompositeConstraint.h; sourceTree = ""; };
48 | A57B4F3D1E84244B008BCF2F /* MASCompositeConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASCompositeConstraint.m; sourceTree = ""; };
49 | A57B4F3E1E84244B008BCF2F /* MASConstraint+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "MASConstraint+Private.h"; sourceTree = ""; };
50 | A57B4F3F1E84244B008BCF2F /* MASConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraint.h; sourceTree = ""; };
51 | A57B4F401E84244B008BCF2F /* MASConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraint.m; sourceTree = ""; };
52 | A57B4F411E84244B008BCF2F /* MASConstraintMaker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASConstraintMaker.h; sourceTree = ""; };
53 | A57B4F421E84244B008BCF2F /* MASConstraintMaker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASConstraintMaker.m; sourceTree = ""; };
54 | A57B4F431E84244B008BCF2F /* MASLayoutConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASLayoutConstraint.h; sourceTree = ""; };
55 | A57B4F441E84244B008BCF2F /* MASLayoutConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASLayoutConstraint.m; sourceTree = ""; };
56 | A57B4F451E84244B008BCF2F /* Masonry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Masonry.h; sourceTree = ""; };
57 | A57B4F461E84244B008BCF2F /* MASUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASUtilities.h; sourceTree = ""; };
58 | A57B4F471E84244B008BCF2F /* MASViewAttribute.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewAttribute.h; sourceTree = ""; };
59 | A57B4F481E84244B008BCF2F /* MASViewAttribute.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewAttribute.m; sourceTree = ""; };
60 | A57B4F491E84244B008BCF2F /* MASViewConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASViewConstraint.h; sourceTree = ""; };
61 | A57B4F4A1E84244B008BCF2F /* MASViewConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASViewConstraint.m; sourceTree = ""; };
62 | A57B4F4B1E84244B008BCF2F /* NSArray+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASAdditions.h"; sourceTree = ""; };
63 | A57B4F4C1E84244B008BCF2F /* NSArray+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+MASAdditions.m"; sourceTree = ""; };
64 | A57B4F4D1E84244B008BCF2F /* NSArray+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+MASShorthandAdditions.h"; sourceTree = ""; };
65 | A57B4F4E1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+MASDebugAdditions.h"; sourceTree = ""; };
66 | A57B4F4F1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+MASDebugAdditions.m"; sourceTree = ""; };
67 | A57B4F501E84244B008BCF2F /* View+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASAdditions.h"; sourceTree = ""; };
68 | A57B4F511E84244B008BCF2F /* View+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "View+MASAdditions.m"; sourceTree = ""; };
69 | A57B4F521E84244B008BCF2F /* View+MASShorthandAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "View+MASShorthandAdditions.h"; sourceTree = ""; };
70 | A57B4F531E84244B008BCF2F /* ViewController+MASAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "ViewController+MASAdditions.h"; sourceTree = ""; };
71 | A57B4F541E84244B008BCF2F /* ViewController+MASAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "ViewController+MASAdditions.m"; sourceTree = ""; };
72 | A5F1D5901E8100BC0047C193 /* Globals.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Globals.h; sourceTree = ""; };
73 | A5F2884A1E88B5DB00193867 /* MoreViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoreViewController.h; sourceTree = ""; };
74 | A5F2884B1E88B5DB00193867 /* MoreViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MoreViewController.m; sourceTree = ""; };
75 | A5F2884E1E88B61300193867 /* 11.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 11.png; sourceTree = ""; };
76 | A5F2884F1E88B61300193867 /* 22.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = 22.png; sourceTree = ""; };
77 | /* End PBXFileReference section */
78 |
79 | /* Begin PBXFrameworksBuildPhase section */
80 | A52B76C31E7FBA6500938AEA /* Frameworks */ = {
81 | isa = PBXFrameworksBuildPhase;
82 | buildActionMask = 2147483647;
83 | files = (
84 | );
85 | runOnlyForDeploymentPostprocessing = 0;
86 | };
87 | /* End PBXFrameworksBuildPhase section */
88 |
89 | /* Begin PBXGroup section */
90 | A52B76BD1E7FBA6500938AEA = {
91 | isa = PBXGroup;
92 | children = (
93 | A52B76E01E7FBA7100938AEA /* WHGradientHelper */,
94 | A52B76C81E7FBA6500938AEA /* Example */,
95 | A52B76C71E7FBA6500938AEA /* Products */,
96 | );
97 | sourceTree = "";
98 | };
99 | A52B76C71E7FBA6500938AEA /* Products */ = {
100 | isa = PBXGroup;
101 | children = (
102 | A52B76C61E7FBA6500938AEA /* Example.app */,
103 | );
104 | name = Products;
105 | sourceTree = "";
106 | };
107 | A52B76C81E7FBA6500938AEA /* Example */ = {
108 | isa = PBXGroup;
109 | children = (
110 | A5F2884D1E88B61300193867 /* imgae */,
111 | A52B76CC1E7FBA6500938AEA /* AppDelegate.h */,
112 | A52B76CD1E7FBA6500938AEA /* AppDelegate.m */,
113 | A52B76CF1E7FBA6500938AEA /* ViewController.h */,
114 | A52B76D01E7FBA6500938AEA /* ViewController.m */,
115 | A5F2884A1E88B5DB00193867 /* MoreViewController.h */,
116 | A5F2884B1E88B5DB00193867 /* MoreViewController.m */,
117 | A5F1D5901E8100BC0047C193 /* Globals.h */,
118 | A57B4F3A1E84244B008BCF2F /* Masonry */,
119 | A52B76D21E7FBA6500938AEA /* Main.storyboard */,
120 | A52B76D51E7FBA6500938AEA /* Assets.xcassets */,
121 | A52B76D71E7FBA6500938AEA /* LaunchScreen.storyboard */,
122 | A52B76DA1E7FBA6600938AEA /* Info.plist */,
123 | A52B76C91E7FBA6500938AEA /* Supporting Files */,
124 | );
125 | path = Example;
126 | sourceTree = "";
127 | };
128 | A52B76C91E7FBA6500938AEA /* Supporting Files */ = {
129 | isa = PBXGroup;
130 | children = (
131 | A52B76CA1E7FBA6500938AEA /* main.m */,
132 | );
133 | name = "Supporting Files";
134 | sourceTree = "";
135 | };
136 | A52B76E01E7FBA7100938AEA /* WHGradientHelper */ = {
137 | isa = PBXGroup;
138 | children = (
139 | A52B76E11E7FBA8900938AEA /* WHGradientHelper.h */,
140 | A52B76E21E7FBA8900938AEA /* WHGradientHelper.m */,
141 | );
142 | name = WHGradientHelper;
143 | path = ../WHGradientHelper;
144 | sourceTree = "";
145 | };
146 | A57B4F3A1E84244B008BCF2F /* Masonry */ = {
147 | isa = PBXGroup;
148 | children = (
149 | A57B4F3B1E84244B008BCF2F /* Info.plist */,
150 | A57B4F3C1E84244B008BCF2F /* MASCompositeConstraint.h */,
151 | A57B4F3D1E84244B008BCF2F /* MASCompositeConstraint.m */,
152 | A57B4F3E1E84244B008BCF2F /* MASConstraint+Private.h */,
153 | A57B4F3F1E84244B008BCF2F /* MASConstraint.h */,
154 | A57B4F401E84244B008BCF2F /* MASConstraint.m */,
155 | A57B4F411E84244B008BCF2F /* MASConstraintMaker.h */,
156 | A57B4F421E84244B008BCF2F /* MASConstraintMaker.m */,
157 | A57B4F431E84244B008BCF2F /* MASLayoutConstraint.h */,
158 | A57B4F441E84244B008BCF2F /* MASLayoutConstraint.m */,
159 | A57B4F451E84244B008BCF2F /* Masonry.h */,
160 | A57B4F461E84244B008BCF2F /* MASUtilities.h */,
161 | A57B4F471E84244B008BCF2F /* MASViewAttribute.h */,
162 | A57B4F481E84244B008BCF2F /* MASViewAttribute.m */,
163 | A57B4F491E84244B008BCF2F /* MASViewConstraint.h */,
164 | A57B4F4A1E84244B008BCF2F /* MASViewConstraint.m */,
165 | A57B4F4B1E84244B008BCF2F /* NSArray+MASAdditions.h */,
166 | A57B4F4C1E84244B008BCF2F /* NSArray+MASAdditions.m */,
167 | A57B4F4D1E84244B008BCF2F /* NSArray+MASShorthandAdditions.h */,
168 | A57B4F4E1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.h */,
169 | A57B4F4F1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.m */,
170 | A57B4F501E84244B008BCF2F /* View+MASAdditions.h */,
171 | A57B4F511E84244B008BCF2F /* View+MASAdditions.m */,
172 | A57B4F521E84244B008BCF2F /* View+MASShorthandAdditions.h */,
173 | A57B4F531E84244B008BCF2F /* ViewController+MASAdditions.h */,
174 | A57B4F541E84244B008BCF2F /* ViewController+MASAdditions.m */,
175 | );
176 | path = Masonry;
177 | sourceTree = "";
178 | };
179 | A5F2884D1E88B61300193867 /* imgae */ = {
180 | isa = PBXGroup;
181 | children = (
182 | A5F2884E1E88B61300193867 /* 11.png */,
183 | A5F2884F1E88B61300193867 /* 22.png */,
184 | );
185 | path = imgae;
186 | sourceTree = "";
187 | };
188 | /* End PBXGroup section */
189 |
190 | /* Begin PBXNativeTarget section */
191 | A52B76C51E7FBA6500938AEA /* Example */ = {
192 | isa = PBXNativeTarget;
193 | buildConfigurationList = A52B76DD1E7FBA6600938AEA /* Build configuration list for PBXNativeTarget "Example" */;
194 | buildPhases = (
195 | A52B76C21E7FBA6500938AEA /* Sources */,
196 | A52B76C31E7FBA6500938AEA /* Frameworks */,
197 | A52B76C41E7FBA6500938AEA /* Resources */,
198 | );
199 | buildRules = (
200 | );
201 | dependencies = (
202 | );
203 | name = Example;
204 | productName = Example;
205 | productReference = A52B76C61E7FBA6500938AEA /* Example.app */;
206 | productType = "com.apple.product-type.application";
207 | };
208 | /* End PBXNativeTarget section */
209 |
210 | /* Begin PBXProject section */
211 | A52B76BE1E7FBA6500938AEA /* Project object */ = {
212 | isa = PBXProject;
213 | attributes = {
214 | LastUpgradeCheck = 0820;
215 | ORGANIZATIONNAME = whbalzac;
216 | TargetAttributes = {
217 | A52B76C51E7FBA6500938AEA = {
218 | CreatedOnToolsVersion = 8.2.1;
219 | ProvisioningStyle = Automatic;
220 | };
221 | };
222 | };
223 | buildConfigurationList = A52B76C11E7FBA6500938AEA /* Build configuration list for PBXProject "Example" */;
224 | compatibilityVersion = "Xcode 3.2";
225 | developmentRegion = English;
226 | hasScannedForEncodings = 0;
227 | knownRegions = (
228 | en,
229 | Base,
230 | );
231 | mainGroup = A52B76BD1E7FBA6500938AEA;
232 | productRefGroup = A52B76C71E7FBA6500938AEA /* Products */;
233 | projectDirPath = "";
234 | projectRoot = "";
235 | targets = (
236 | A52B76C51E7FBA6500938AEA /* Example */,
237 | );
238 | };
239 | /* End PBXProject section */
240 |
241 | /* Begin PBXResourcesBuildPhase section */
242 | A52B76C41E7FBA6500938AEA /* Resources */ = {
243 | isa = PBXResourcesBuildPhase;
244 | buildActionMask = 2147483647;
245 | files = (
246 | A5F288501E88B61300193867 /* 11.png in Resources */,
247 | A5F288511E88B61300193867 /* 22.png in Resources */,
248 | A57B4F551E84244B008BCF2F /* Info.plist in Resources */,
249 | A52B76D91E7FBA6500938AEA /* LaunchScreen.storyboard in Resources */,
250 | A52B76D61E7FBA6500938AEA /* Assets.xcassets in Resources */,
251 | A52B76D41E7FBA6500938AEA /* Main.storyboard in Resources */,
252 | );
253 | runOnlyForDeploymentPostprocessing = 0;
254 | };
255 | /* End PBXResourcesBuildPhase section */
256 |
257 | /* Begin PBXSourcesBuildPhase section */
258 | A52B76C21E7FBA6500938AEA /* Sources */ = {
259 | isa = PBXSourcesBuildPhase;
260 | buildActionMask = 2147483647;
261 | files = (
262 | A57B4F581E84244B008BCF2F /* MASConstraintMaker.m in Sources */,
263 | A52B76D11E7FBA6500938AEA /* ViewController.m in Sources */,
264 | A52B76CE1E7FBA6500938AEA /* AppDelegate.m in Sources */,
265 | A57B4F571E84244B008BCF2F /* MASConstraint.m in Sources */,
266 | A5F2884C1E88B5DB00193867 /* MoreViewController.m in Sources */,
267 | A57B4F5F1E84244B008BCF2F /* ViewController+MASAdditions.m in Sources */,
268 | A57B4F591E84244B008BCF2F /* MASLayoutConstraint.m in Sources */,
269 | A57B4F5C1E84244B008BCF2F /* NSArray+MASAdditions.m in Sources */,
270 | A57B4F5B1E84244B008BCF2F /* MASViewConstraint.m in Sources */,
271 | A57B4F5A1E84244B008BCF2F /* MASViewAttribute.m in Sources */,
272 | A57B4F5E1E84244B008BCF2F /* View+MASAdditions.m in Sources */,
273 | A52B76E31E7FBA8900938AEA /* WHGradientHelper.m in Sources */,
274 | A52B76CB1E7FBA6500938AEA /* main.m in Sources */,
275 | A57B4F561E84244B008BCF2F /* MASCompositeConstraint.m in Sources */,
276 | A57B4F5D1E84244B008BCF2F /* NSLayoutConstraint+MASDebugAdditions.m in Sources */,
277 | );
278 | runOnlyForDeploymentPostprocessing = 0;
279 | };
280 | /* End PBXSourcesBuildPhase section */
281 |
282 | /* Begin PBXVariantGroup section */
283 | A52B76D21E7FBA6500938AEA /* Main.storyboard */ = {
284 | isa = PBXVariantGroup;
285 | children = (
286 | A52B76D31E7FBA6500938AEA /* Base */,
287 | );
288 | name = Main.storyboard;
289 | sourceTree = "";
290 | };
291 | A52B76D71E7FBA6500938AEA /* LaunchScreen.storyboard */ = {
292 | isa = PBXVariantGroup;
293 | children = (
294 | A52B76D81E7FBA6500938AEA /* Base */,
295 | );
296 | name = LaunchScreen.storyboard;
297 | sourceTree = "";
298 | };
299 | /* End PBXVariantGroup section */
300 |
301 | /* Begin XCBuildConfiguration section */
302 | A52B76DB1E7FBA6600938AEA /* Debug */ = {
303 | isa = XCBuildConfiguration;
304 | buildSettings = {
305 | ALWAYS_SEARCH_USER_PATHS = NO;
306 | CLANG_ANALYZER_NONNULL = YES;
307 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
308 | CLANG_CXX_LIBRARY = "libc++";
309 | CLANG_ENABLE_MODULES = YES;
310 | CLANG_ENABLE_OBJC_ARC = YES;
311 | CLANG_WARN_BOOL_CONVERSION = YES;
312 | CLANG_WARN_CONSTANT_CONVERSION = YES;
313 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
314 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
315 | CLANG_WARN_EMPTY_BODY = YES;
316 | CLANG_WARN_ENUM_CONVERSION = YES;
317 | CLANG_WARN_INFINITE_RECURSION = YES;
318 | CLANG_WARN_INT_CONVERSION = YES;
319 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
320 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
321 | CLANG_WARN_UNREACHABLE_CODE = YES;
322 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
323 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
324 | COPY_PHASE_STRIP = NO;
325 | DEBUG_INFORMATION_FORMAT = dwarf;
326 | ENABLE_STRICT_OBJC_MSGSEND = YES;
327 | ENABLE_TESTABILITY = YES;
328 | GCC_C_LANGUAGE_STANDARD = gnu99;
329 | GCC_DYNAMIC_NO_PIC = NO;
330 | GCC_NO_COMMON_BLOCKS = YES;
331 | GCC_OPTIMIZATION_LEVEL = 0;
332 | GCC_PREPROCESSOR_DEFINITIONS = (
333 | "DEBUG=1",
334 | "$(inherited)",
335 | );
336 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
337 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
338 | GCC_WARN_UNDECLARED_SELECTOR = YES;
339 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
340 | GCC_WARN_UNUSED_FUNCTION = YES;
341 | GCC_WARN_UNUSED_VARIABLE = YES;
342 | IPHONEOS_DEPLOYMENT_TARGET = 10.2;
343 | MTL_ENABLE_DEBUG_INFO = YES;
344 | ONLY_ACTIVE_ARCH = YES;
345 | SDKROOT = iphoneos;
346 | TARGETED_DEVICE_FAMILY = "1,2";
347 | };
348 | name = Debug;
349 | };
350 | A52B76DC1E7FBA6600938AEA /* Release */ = {
351 | isa = XCBuildConfiguration;
352 | buildSettings = {
353 | ALWAYS_SEARCH_USER_PATHS = NO;
354 | CLANG_ANALYZER_NONNULL = YES;
355 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
356 | CLANG_CXX_LIBRARY = "libc++";
357 | CLANG_ENABLE_MODULES = YES;
358 | CLANG_ENABLE_OBJC_ARC = YES;
359 | CLANG_WARN_BOOL_CONVERSION = YES;
360 | CLANG_WARN_CONSTANT_CONVERSION = YES;
361 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
362 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
363 | CLANG_WARN_EMPTY_BODY = YES;
364 | CLANG_WARN_ENUM_CONVERSION = YES;
365 | CLANG_WARN_INFINITE_RECURSION = YES;
366 | CLANG_WARN_INT_CONVERSION = YES;
367 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
368 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
369 | CLANG_WARN_UNREACHABLE_CODE = YES;
370 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
371 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
372 | COPY_PHASE_STRIP = NO;
373 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
374 | ENABLE_NS_ASSERTIONS = NO;
375 | ENABLE_STRICT_OBJC_MSGSEND = YES;
376 | GCC_C_LANGUAGE_STANDARD = gnu99;
377 | GCC_NO_COMMON_BLOCKS = YES;
378 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
379 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
380 | GCC_WARN_UNDECLARED_SELECTOR = YES;
381 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
382 | GCC_WARN_UNUSED_FUNCTION = YES;
383 | GCC_WARN_UNUSED_VARIABLE = YES;
384 | IPHONEOS_DEPLOYMENT_TARGET = 10.2;
385 | MTL_ENABLE_DEBUG_INFO = NO;
386 | SDKROOT = iphoneos;
387 | TARGETED_DEVICE_FAMILY = "1,2";
388 | VALIDATE_PRODUCT = YES;
389 | };
390 | name = Release;
391 | };
392 | A52B76DE1E7FBA6600938AEA /* Debug */ = {
393 | isa = XCBuildConfiguration;
394 | buildSettings = {
395 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
396 | INFOPLIST_FILE = Example/Info.plist;
397 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
398 | PRODUCT_BUNDLE_IDENTIFIER = whbalzac.Example;
399 | PRODUCT_NAME = "$(TARGET_NAME)";
400 | };
401 | name = Debug;
402 | };
403 | A52B76DF1E7FBA6600938AEA /* Release */ = {
404 | isa = XCBuildConfiguration;
405 | buildSettings = {
406 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
407 | INFOPLIST_FILE = Example/Info.plist;
408 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
409 | PRODUCT_BUNDLE_IDENTIFIER = whbalzac.Example;
410 | PRODUCT_NAME = "$(TARGET_NAME)";
411 | };
412 | name = Release;
413 | };
414 | /* End XCBuildConfiguration section */
415 |
416 | /* Begin XCConfigurationList section */
417 | A52B76C11E7FBA6500938AEA /* Build configuration list for PBXProject "Example" */ = {
418 | isa = XCConfigurationList;
419 | buildConfigurations = (
420 | A52B76DB1E7FBA6600938AEA /* Debug */,
421 | A52B76DC1E7FBA6600938AEA /* Release */,
422 | );
423 | defaultConfigurationIsVisible = 0;
424 | defaultConfigurationName = Release;
425 | };
426 | A52B76DD1E7FBA6600938AEA /* Build configuration list for PBXNativeTarget "Example" */ = {
427 | isa = XCConfigurationList;
428 | buildConfigurations = (
429 | A52B76DE1E7FBA6600938AEA /* Debug */,
430 | A52B76DF1E7FBA6600938AEA /* Release */,
431 | );
432 | defaultConfigurationIsVisible = 0;
433 | defaultConfigurationName = Release;
434 | };
435 | /* End XCConfigurationList section */
436 | };
437 | rootObject = A52B76BE1E7FBA6500938AEA /* Project object */;
438 | }
439 |
--------------------------------------------------------------------------------