Browse Source

layout guides example

Jonas Budelmann 11 years ago
parent
commit
f394bdf255

+ 6 - 0
MasonryExamples/Masonry iOS Examples.xcodeproj/project.pbxproj

@@ -19,6 +19,7 @@
 		DD52F253179CADC0005CD195 /* MASExampleListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F24C179CADC0005CD195 /* MASExampleListViewController.m */; };
 		DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F24E179CADC0005CD195 /* MASExampleSidesView.m */; };
 		DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD52F250179CADC0005CD195 /* MASExampleViewController.m */; };
+		DD653E4A1843E61500D1EC5A /* MASExampleLayoutGuideViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD653E491843E61500D1EC5A /* MASExampleLayoutGuideViewController.m */; };
 		DD7CC17617ACE990007A469E /* MASExampleDebuggingView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD7CC17517ACE990007A469E /* MASExampleDebuggingView.m */; };
 		DD9B4D35183CC980002BF408 /* MASExampleScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = DD9B4D34183CC980002BF408 /* MASExampleScrollView.m */; };
 		DDA5755F17C1B07E0010F88E /* MASCompositeConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = DDA5754D17C1B07E0010F88E /* MASCompositeConstraint.m */; };
@@ -55,6 +56,8 @@
 		DD52F24E179CADC0005CD195 /* MASExampleSidesView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleSidesView.m; sourceTree = "<group>"; };
 		DD52F24F179CADC0005CD195 /* MASExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleViewController.h; sourceTree = "<group>"; };
 		DD52F250179CADC0005CD195 /* MASExampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleViewController.m; sourceTree = "<group>"; };
+		DD653E481843E61500D1EC5A /* MASExampleLayoutGuideViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleLayoutGuideViewController.h; sourceTree = "<group>"; };
+		DD653E491843E61500D1EC5A /* MASExampleLayoutGuideViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleLayoutGuideViewController.m; sourceTree = "<group>"; };
 		DD7CC17417ACE990007A469E /* MASExampleDebuggingView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleDebuggingView.h; sourceTree = "<group>"; };
 		DD7CC17517ACE990007A469E /* MASExampleDebuggingView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleDebuggingView.m; sourceTree = "<group>"; };
 		DD9B4D33183CC980002BF408 /* MASExampleScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleScrollView.h; sourceTree = "<group>"; };
@@ -178,6 +181,8 @@
 				DD52F24C179CADC0005CD195 /* MASExampleListViewController.m */,
 				DD52F24F179CADC0005CD195 /* MASExampleViewController.h */,
 				DD52F250179CADC0005CD195 /* MASExampleViewController.m */,
+				DD653E481843E61500D1EC5A /* MASExampleLayoutGuideViewController.h */,
+				DD653E491843E61500D1EC5A /* MASExampleLayoutGuideViewController.m */,
 			);
 			name = Controllers;
 			sourceTree = "<group>";
@@ -275,6 +280,7 @@
 				DD52F237179CAD57005CD195 /* main.m in Sources */,
 				DD52F23B179CAD57005CD195 /* MASAppDelegate.m in Sources */,
 				DD52F251179CADC0005CD195 /* MASExampleBasicView.m in Sources */,
+				DD653E4A1843E61500D1EC5A /* MASExampleLayoutGuideViewController.m in Sources */,
 				DDDF60CC181915E300BF7B8B /* MASExampleLabelView.m in Sources */,
 				DD52F252179CADC0005CD195 /* MASExampleConstantsView.m in Sources */,
 				DD52F253179CADC0005CD195 /* MASExampleListViewController.m in Sources */,

+ 13 - 0
MasonryExamples/Masonry iOS Examples/MASExampleLayoutGuideViewController.h

@@ -0,0 +1,13 @@
+//
+//  MASExampleLayoutGuideViewController.h
+//  Masonry iOS Examples
+//
+//  Created by Jonas Budelmann on 26/11/13.
+//  Copyright (c) 2013 Jonas Budelmann. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface MASExampleLayoutGuideViewController : UIViewController
+
+@end

+ 63 - 0
MasonryExamples/Masonry iOS Examples/MASExampleLayoutGuideViewController.m

@@ -0,0 +1,63 @@
+//
+//  MASExampleLayoutGuideViewController.m
+//  Masonry iOS Examples
+//
+//  Created by Jonas Budelmann on 26/11/13.
+//  Copyright (c) 2013 Jonas Budelmann. All rights reserved.
+//
+
+#import "MASExampleLayoutGuideViewController.h"
+
+@interface MASExampleLayoutGuideViewController ()
+
+@end
+
+@implementation MASExampleLayoutGuideViewController
+
+- (id)init {
+    self = [super init];
+    if (!self) return nil;
+
+    self.title = @"Layout Guides";
+
+    return self;
+}
+
+- (void)viewDidLoad {
+    [super viewDidLoad];
+
+    self.view.backgroundColor = [UIColor whiteColor];
+
+    UIView *topView = UIView.new;
+    topView.backgroundColor = UIColor.greenColor;
+    topView.layer.borderColor = UIColor.blackColor.CGColor;
+    topView.layer.borderWidth = 2;
+    [self.view addSubview:topView];
+
+    UIView *bottomView = UIView.new;
+    bottomView.backgroundColor = UIColor.redColor;
+    bottomView.layer.borderColor = UIColor.blackColor.CGColor;
+    bottomView.layer.borderWidth = 2;
+    [self.view addSubview:bottomView];
+
+    // TODO find way that avoids casting
+    // layoutGuides are actually UIView subclasses so can be used in Masonry
+    // However casting to UIView is not ideal if Apple decides to change underlying implementation of layoutGuides this will break
+    [topView makeConstraints:^(MASConstraintMaker *make) {
+        UIView *topLayoutGuide = (id)self.topLayoutGuide;
+        make.top.equalTo(topLayoutGuide.bottom);
+        make.left.equalTo(self.view);
+        make.right.equalTo(self.view);
+        make.height.equalTo(@40);
+    }];
+
+    [bottomView makeConstraints:^(MASConstraintMaker *make) {
+        UIView *bottomLayoutGuide = (id)self.bottomLayoutGuide;
+        make.bottom.equalTo(bottomLayoutGuide.top);
+        make.left.equalTo(self.view);
+        make.right.equalTo(self.view);
+        make.height.equalTo(@40);
+    }];
+}
+
+@end

+ 4 - 1
MasonryExamples/Masonry iOS Examples/MASExampleListViewController.m

@@ -16,6 +16,7 @@
 #import "MASExampleLabelView.h"
 #import "MASExampleUpdateView.h"
 #import "MASExampleScrollView.h"
+#import "MASExampleLayoutGuideViewController.h"
 
 static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
 
@@ -50,6 +51,7 @@ static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
                                               viewClass:MASExampleLabelView.class],
         [[MASExampleViewController alloc] initWithTitle:@"UIScrollView"
                                               viewClass:MASExampleScrollView.class],
+        [[MASExampleLayoutGuideViewController alloc] init],
     ];
     
     return self;
@@ -57,7 +59,8 @@ static NSString * const kMASCellReuseIdentifier = @"kMASCellReuseIdentifier";
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    
+
+    self.view.backgroundColor = [UIColor whiteColor];
     [self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:kMASCellReuseIdentifier];
 }