Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support layout margins guide #597

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Examples/Masonry iOS Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
00FC4A321B7359D700DCA999 /* MASExampleDistributeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 00FC4A311B7359D700DCA999 /* MASExampleDistributeView.m */; };
166B36CA26A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 166B36C926A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m */; };
27A27D461A6CF0C400D34F52 /* MASExampleAspectFitView.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A27D451A6CF0C400D34F52 /* MASExampleAspectFitView.m */; };
3C02224919D0C4EC00507321 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3C02224819D0C4EC00507321 /* Images.xcassets */; };
3DB1CAD5184538E200E91FC5 /* MASExampleArrayView.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB1CAD4184538E200E91FC5 /* MASExampleArrayView.m */; };
Expand Down Expand Up @@ -39,6 +40,8 @@
/* Begin PBXFileReference section */
00FC4A301B7359D700DCA999 /* MASExampleDistributeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleDistributeView.h; sourceTree = "<group>"; };
00FC4A311B7359D700DCA999 /* MASExampleDistributeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleDistributeView.m; sourceTree = "<group>"; };
166B36C826A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASExampleLayoutMarginsGuideViewController.h; sourceTree = "<group>"; };
166B36C926A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASExampleLayoutMarginsGuideViewController.m; sourceTree = "<group>"; };
27A27D441A6CF0C400D34F52 /* MASExampleAspectFitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleAspectFitView.h; sourceTree = "<group>"; };
27A27D451A6CF0C400D34F52 /* MASExampleAspectFitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleAspectFitView.m; sourceTree = "<group>"; };
321AA59CF7B045B6D503D2E5 /* Pods-Masonry iOS Examples.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Masonry iOS Examples.release.xcconfig"; path = "../Pods/Target Support Files/Pods-Masonry iOS Examples/Pods-Masonry iOS Examples.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -205,6 +208,8 @@
DD653E491843E61500D1EC5A /* MASExampleLayoutGuideViewController.m */,
DFBACE571F7B76E30047F15A /* MASExampleSafeAreaLayoutGuideViewController.h */,
DFBACE581F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m */,
166B36C826A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.h */,
166B36C926A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m */,
);
name = Controllers;
sourceTree = "<group>";
Expand Down Expand Up @@ -256,6 +261,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = DD52F21E179CAD57005CD195;
Expand Down Expand Up @@ -353,6 +359,7 @@
DD52F254179CADC0005CD195 /* MASExampleSidesView.m in Sources */,
DD32C3FD18E8BFF6001F6AD2 /* MASExampleAttributeChainingView.m in Sources */,
DD52F255179CADC0005CD195 /* MASExampleViewController.m in Sources */,
166B36CA26A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m in Sources */,
DDF3875C179D648D00178773 /* MASExampleAnimatedView.m in Sources */,
DD7CC17617ACE990007A469E /* MASExampleDebuggingView.m in Sources */,
4BEB55B61957394E008C862B /* MASExampleRemakeView.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// MASExampleLayoutMarginsGuideViewController.h
// Masonry iOS Examples
//
// Created by Chase Choi on 2021/7/20.
// Copyright © 2021 Jonas Budelmann. All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface MASExampleLayoutMarginsGuideViewController : UIViewController

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
//
// MASExampleLayoutMarginsGuideViewController.m
// Masonry iOS Examples
//
// Created by Chase Choi on 2021/7/20.
// Copyright © 2021 Jonas Budelmann. All rights reserved.
//

#import "MASExampleLayoutMarginsGuideViewController.h"

@interface MASExampleLayoutMarginsGuideViewController ()

@end

@implementation MASExampleLayoutMarginsGuideViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"Layout Margins Guides";
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];

UIView *view1 = [UIView new];
view1.backgroundColor = [UIColor redColor];
[self.view addSubview:view1];

UIView *view2 = [UIView new];
view2.backgroundColor = [UIColor greenColor];
[self.view addSubview:view2];

UIView *view3 = [UIView new];
view3.backgroundColor = [UIColor blueColor];
[self.view addSubview:view3];

UIView *leftView = [self viewWithName:@"LY"];
UIView *rightView = [self viewWithName:@"RY"];
UIView *topView = [self viewWithName:@"TX"];
UIView *bottomView = [self viewWithName:@"BX"];

UIView *leftTopView = [self viewWithName:@"LT"];
UIView *rightTopView = [self viewWithName:@"RT"];
UIView *leftBottomView = [self viewWithName:@"LB"];
UIView *rightBottomView = [self viewWithName:@"RB"];

UIView *centerView = [self viewWithName:@"XY"];

const CGFloat size = 50.0;

[view1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view.mas_layoutMarginsGuide).inset(10.0);
}];

[view2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view.mas_layoutMarginsGuide);
make.width.height.equalTo(self.view.mas_layoutMarginsGuide).sizeOffset(CGSizeMake(- 40.0, - 40.0));
}];

[view3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view.mas_layoutMarginsGuide);
make.width.equalTo(self.view.mas_layoutMarginsGuide).sizeOffset(CGSizeMake(- 60.0, - 60.0));
make.height.equalTo(self.view.mas_layoutMarginsGuide).sizeOffset(CGSizeMake(- 60.0, - 60.0));
}];

[leftTopView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(self.view.mas_layoutMarginsGuide);
make.width.height.equalTo(@(size));
}];

[rightTopView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.mas_layoutMarginsGuideRight);
make.top.equalTo(self.view.mas_layoutMarginsGuideTop);
make.width.height.equalTo(@(size));
}];

[leftBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view.mas_layoutMarginsGuideLeft);
make.bottom.equalTo(self.view.mas_layoutMarginsGuideBottom);
make.width.height.equalTo(@(size));
}];

[rightBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.bottom.equalTo(self.view.mas_layoutMarginsGuide);
make.width.height.equalTo(@(size));
}];

[leftView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.centerY.equalTo(self.view.mas_layoutMarginsGuide);
make.width.height.equalTo(@(size));
}];

[rightView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.view.mas_layoutMarginsGuideRight);
make.centerY.equalTo(self.view.mas_layoutMarginsGuideCenterY);
make.width.height.equalTo(@(size));
}];

[topView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_layoutMarginsGuideTop);
make.centerX.equalTo(self.view.mas_layoutMarginsGuideCenterX);
make.width.height.equalTo(@(size));
}];

[bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.centerX.equalTo(self.view.mas_layoutMarginsGuide);
make.width.height.equalTo(@(size));
}];

[centerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view.mas_layoutMarginsGuide);
make.width.height.equalTo(@(size));
}];
}

- (UIView *)viewWithName:(NSString *)name {
UILabel *label = [UILabel new];
label.text = name;
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor yellowColor];
[self.view addSubview:label];
return label;
}

@end
6 changes: 6 additions & 0 deletions Examples/Masonry iOS Examples/MASExampleListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#import "MASExampleScrollView.h"
#import "MASExampleLayoutGuideViewController.h"
#import "MASExampleSafeAreaLayoutGuideViewController.h"
#import "MASExampleLayoutMarginsGuideViewController.h"
#import "MASExampleArrayView.h"
#import "MASExampleAttributeChainingView.h"
#import "MASExampleAspectFitView.h"
Expand Down Expand Up @@ -83,6 +84,11 @@ - (id)init {
self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleSafeAreaLayoutGuideViewController alloc] init]];
}

if ([UIView instancesRespondToSelector:@selector(layoutMarginsGuide)])
{
self.exampleControllers = [self.exampleControllers arrayByAddingObject:[[MASExampleLayoutMarginsGuideViewController alloc] init]];
}

return self;
}

Expand Down
12 changes: 12 additions & 0 deletions Masonry/View+MASAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);

@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuide NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideLeading NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideTrailing NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideLeft NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideRight NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideTop NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideBottom NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideWidth NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideHeight NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideCenterX NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *mas_layoutMarginsGuideCenterY NS_AVAILABLE_IOS(9.0);

#endif

/**
Expand Down
44 changes: 44 additions & 0 deletions Masonry/View+MASAdditions.m
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,50 @@ - (MASViewAttribute *)mas_safeAreaLayoutGuideCenterY {
return [[MASViewAttribute alloc] initWithView:self item:self.safeAreaLayoutGuide layoutAttribute:NSLayoutAttributeCenterY];
}

- (MASViewAttribute *)mas_layoutMarginsGuide {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeNotAnAttribute];
}

- (MASViewAttribute *)mas_layoutMarginsGuideLeading {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeLeading];
}

- (MASViewAttribute *)mas_layoutMarginsGuideTrailing {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeTrailing];
}

- (MASViewAttribute *)mas_layoutMarginsGuideLeft {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeLeft];
}

- (MASViewAttribute *)mas_layoutMarginsGuideRight {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeRight];
}

- (MASViewAttribute *)mas_layoutMarginsGuideTop {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeTop];
}

- (MASViewAttribute *)mas_layoutMarginsGuideBottom {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeBottom];
}

- (MASViewAttribute *)mas_layoutMarginsGuideWidth {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeWidth];
}

- (MASViewAttribute *)mas_layoutMarginsGuideHeight {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeHeight];
}

- (MASViewAttribute *)mas_layoutMarginsGuideCenterX {
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeCenterX];
}

- (MASViewAttribute *)mas_layoutMarginsGuideCenterY{
return [[MASViewAttribute alloc] initWithView:self item:self.layoutMarginsGuide layoutAttribute:NSLayoutAttributeCenterY];
}

#endif

#pragma mark - associated properties
Expand Down
22 changes: 22 additions & 0 deletions Masonry/View+MASShorthandAdditions.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterX NS_AVAILABLE_IOS(11.0);
@property (nonatomic, strong, readonly) MASViewAttribute *safeAreaLayoutGuideCenterY NS_AVAILABLE_IOS(11.0);

@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideLeading NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideTrailing NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideLeft NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideRight NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideTop NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideBottom NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideWidth NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideHeight NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideCenterX NS_AVAILABLE_IOS(9.0);
@property (nonatomic, strong, readonly) MASViewAttribute *layoutMarginsGuideCenterY NS_AVAILABLE_IOS(9.0);

#endif

- (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
Expand Down Expand Up @@ -115,6 +126,17 @@ MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideHeight, NS_AVAILABLE_IOS(11.0));
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterX, NS_AVAILABLE_IOS(11.0));
MAS_ATTR_FORWARD_AVAILABLE(safeAreaLayoutGuideCenterY, NS_AVAILABLE_IOS(11.0));

MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideLeading, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideTrailing, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideLeft, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideRight, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideTop, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideBottom, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideWidth, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideHeight, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideCenterX, NS_AVAILABLE_IOS(9.0));
MAS_ATTR_FORWARD_AVAILABLE(layoutMarginsGuideCenterY, NS_AVAILABLE_IOS(9.0));

#endif

- (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
Expand Down