From 352056a964c3330561e09e1259a0982f5144e3f8 Mon Sep 17 00:00:00 2001 From: Montak Oleg Date: Fri, 2 Oct 2015 22:49:05 +0300 Subject: [PATCH] Add fillSuperView with paddings method --- Facade/UIView+Facade.h | 1 + Facade/UIView+Facade.m | 7 +++++++ FacadeTests/FacadeTests.m | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/Facade/UIView+Facade.h b/Facade/UIView+Facade.h index a6a9540..903d94a 100644 --- a/Facade/UIView+Facade.h +++ b/Facade/UIView+Facade.h @@ -26,6 +26,7 @@ #pragma mark - Fill superview - (void)fillSuperview; +- (void)fillSuperviewWithLeftPadding:(CGFloat)left rightPadding:(CGFloat)right topPadding:(CGFloat)top bottomPadding:(CGFloat)bottom; #pragma mark - Corner alignment diff --git a/Facade/UIView+Facade.m b/Facade/UIView+Facade.m index b91ed32..3afc705 100644 --- a/Facade/UIView+Facade.m +++ b/Facade/UIView+Facade.m @@ -46,6 +46,13 @@ - (void)fillSuperview { self.frame = CGRectMake(0, 0, CGRectGetWidth(self.superview.frame), CGRectGetHeight(self.superview.frame)); } +- (void)fillSuperviewWithLeftPadding:(CGFloat)left rightPadding:(CGFloat)right topPadding:(CGFloat)top bottomPadding:(CGFloat)bottom { + CGFloat width = CGRectGetWidth(self.superview.frame) - (left + right); + CGFloat height = CGRectGetHeight(self.superview.frame) - (top + bottom); + + self.frame = CGRectMake(left, top, width, height); +} + #pragma mark - Corner alignment - (void)anchorTopLeftWithLeftPadding:(CGFloat)left topPadding:(CGFloat)top width:(CGFloat)width height:(CGFloat)height { diff --git a/FacadeTests/FacadeTests.m b/FacadeTests/FacadeTests.m index 7a7e939..bf2299d 100644 --- a/FacadeTests/FacadeTests.m +++ b/FacadeTests/FacadeTests.m @@ -120,6 +120,12 @@ - (void)testFillSuperview { XCTAssertTrue(CGRectEqualToRect(_candidateView.frame, CGRectMake(0, 0, 1000, 1000))); } +- (void)testFillSuperViewWithPaddings { + [_candidateView fillSuperviewWithLeftPadding:10 rightPadding:20 topPadding:30 bottomPadding:40]; + + XCTAssertTrue(CGRectEqualToRect(_candidateView.frame, CGRectMake(10, 30, 970, 930))); +} + #pragma mark - Corner alignment