diff --git a/Examples/Masonry iOS Examples.xcodeproj/project.pbxproj b/Examples/Masonry iOS Examples.xcodeproj/project.pbxproj index 8ea63a4f..3e43d1f4 100644 --- a/Examples/Masonry iOS Examples.xcodeproj/project.pbxproj +++ b/Examples/Masonry iOS Examples.xcodeproj/project.pbxproj @@ -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 */; }; @@ -39,6 +40,8 @@ /* Begin PBXFileReference section */ 00FC4A301B7359D700DCA999 /* MASExampleDistributeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleDistributeView.h; sourceTree = ""; }; 00FC4A311B7359D700DCA999 /* MASExampleDistributeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleDistributeView.m; sourceTree = ""; }; + 166B36C826A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MASExampleLayoutMarginsGuideViewController.h; sourceTree = ""; }; + 166B36C926A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MASExampleLayoutMarginsGuideViewController.m; sourceTree = ""; }; 27A27D441A6CF0C400D34F52 /* MASExampleAspectFitView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MASExampleAspectFitView.h; sourceTree = ""; }; 27A27D451A6CF0C400D34F52 /* MASExampleAspectFitView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MASExampleAspectFitView.m; sourceTree = ""; }; 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 = ""; }; @@ -205,6 +208,8 @@ DD653E491843E61500D1EC5A /* MASExampleLayoutGuideViewController.m */, DFBACE571F7B76E30047F15A /* MASExampleSafeAreaLayoutGuideViewController.h */, DFBACE581F7B76E40047F15A /* MASExampleSafeAreaLayoutGuideViewController.m */, + 166B36C826A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.h */, + 166B36C926A7042100A8C4C6 /* MASExampleLayoutMarginsGuideViewController.m */, ); name = Controllers; sourceTree = ""; @@ -256,6 +261,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = DD52F21E179CAD57005CD195; @@ -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 */, diff --git a/Examples/Masonry iOS Examples/MASExampleLayoutMarginsGuideViewController.h b/Examples/Masonry iOS Examples/MASExampleLayoutMarginsGuideViewController.h new file mode 100644 index 00000000..302081ea --- /dev/null +++ b/Examples/Masonry iOS Examples/MASExampleLayoutMarginsGuideViewController.h @@ -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 + +NS_ASSUME_NONNULL_BEGIN + +@interface MASExampleLayoutMarginsGuideViewController : UIViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/Examples/Masonry iOS Examples/MASExampleLayoutMarginsGuideViewController.m b/Examples/Masonry iOS Examples/MASExampleLayoutMarginsGuideViewController.m new file mode 100644 index 00000000..1ec5ef19 --- /dev/null +++ b/Examples/Masonry iOS Examples/MASExampleLayoutMarginsGuideViewController.m @@ -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 diff --git a/Examples/Masonry iOS Examples/MASExampleListViewController.m b/Examples/Masonry iOS Examples/MASExampleListViewController.m index 7e3d05c5..88ac33eb 100644 --- a/Examples/Masonry iOS Examples/MASExampleListViewController.m +++ b/Examples/Masonry iOS Examples/MASExampleListViewController.m @@ -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" @@ -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; } diff --git a/Masonry/View+MASAdditions.h b/Masonry/View+MASAdditions.h index 00477c1c..53f1b51d 100644 --- a/Masonry/View+MASAdditions.h +++ b/Masonry/View+MASAdditions.h @@ -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 /** diff --git a/Masonry/View+MASAdditions.m b/Masonry/View+MASAdditions.m index b99316ad..d90e4646 100644 --- a/Masonry/View+MASAdditions.m +++ b/Masonry/View+MASAdditions.m @@ -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 diff --git a/Masonry/View+MASShorthandAdditions.h b/Masonry/View+MASShorthandAdditions.h index 8e375ee3..68249ff4 100644 --- a/Masonry/View+MASShorthandAdditions.h +++ b/Masonry/View+MASShorthandAdditions.h @@ -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; @@ -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 {