UIView+Layout.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //
  2. // UIView+Layout.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 7/18/19.
  6. //Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "UIView+Layout.h"
  9. @implementation UIView (Layout)
  10. - (void)centerInView:(UIView *)view {
  11. [self.centerXAnchor constraintEqualToAnchor:view.centerXAnchor].active = YES;
  12. [self.centerYAnchor constraintEqualToAnchor:view.centerYAnchor].active = YES;
  13. }
  14. - (void)pinEdgesTo:(UIView *)view {
  15. [self.topAnchor constraintEqualToAnchor:view.topAnchor].active = YES;
  16. [self.leftAnchor constraintEqualToAnchor:view.leftAnchor].active = YES;
  17. [self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor].active = YES;
  18. [self.rightAnchor constraintEqualToAnchor:view.rightAnchor].active = YES;
  19. }
  20. - (void)pinEdgesTo:(UIView *)view withInsets:(UIEdgeInsets)i {
  21. [self.topAnchor constraintEqualToAnchor:view.topAnchor constant:i.top].active = YES;
  22. [self.leftAnchor constraintEqualToAnchor:view.leftAnchor constant:i.left].active = YES;
  23. [self.bottomAnchor constraintEqualToAnchor:view.bottomAnchor constant:-i.bottom].active = YES;
  24. [self.rightAnchor constraintEqualToAnchor:view.rightAnchor constant:-i.right].active = YES;
  25. }
  26. - (void)pinEdgesToSuperview {
  27. [self pinEdgesTo:self.superview];
  28. }
  29. - (void)pinEdgesToSuperviewWithInsets:(UIEdgeInsets)insets {
  30. [self pinEdgesTo:self.superview withInsets:insets];
  31. }
  32. @end