Skip to content

Instantly share code, notes, and snippets.

@scorpiozj
Forked from nfarina/UIView+FrameAdditions.h
Created October 21, 2013 05:28
Show Gist options
  • Select an option

  • Save scorpiozj/7079077 to your computer and use it in GitHub Desktop.

Select an option

Save scorpiozj/7079077 to your computer and use it in GitHub Desktop.

Revisions

  1. @nfarina nfarina revised this gist Aug 22, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions UIView+FrameAdditions.m
    Original file line number Diff line number Diff line change
    @@ -21,15 +21,15 @@ - (void)set$width:(CGFloat)width { self.frame = (CGRect){ .origin=self.frame.ori
    - (void)set$height:(CGFloat)height { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=self.frame.size.width, .size.height=height }; }

    - (CGFloat)$left { return self.frame.origin.x; }
    - (void)set$left:(CGFloat)left { self.frame = (CGRect){ .origin.x=left, .origin.y=self.frame.origin.y, .size.width=MAX(self.frame.origin.x+self.frame.size.width-left,0), .size.height=self.frame.size.height }; }
    - (void)set$left:(CGFloat)left { self.frame = (CGRect){ .origin.x=left, .origin.y=self.frame.origin.y, .size.width=fmaxf(self.frame.origin.x+self.frame.size.width-left,0), .size.height=self.frame.size.height }; }

    - (CGFloat)$top { return self.frame.origin.y; }
    - (void)set$top:(CGFloat)top { self.frame = (CGRect){ .origin.x=self.frame.origin.x, .origin.y=top, .size.width=self.frame.size.width, .size.height=MAX(self.frame.origin.y+self.frame.size.height-top,0) }; }
    - (void)set$top:(CGFloat)top { self.frame = (CGRect){ .origin.x=self.frame.origin.x, .origin.y=top, .size.width=self.frame.size.width, .size.height=fmaxf(self.frame.origin.y+self.frame.size.height-top,0) }; }

    - (CGFloat)$right { return self.frame.origin.x + self.frame.size.width; }
    - (void)set$right:(CGFloat)right { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=MAX(right-self.frame.origin.x,0), .size.height=self.frame.size.height }; }
    - (void)set$right:(CGFloat)right { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=fmaxf(right-self.frame.origin.x,0), .size.height=self.frame.size.height }; }

    - (CGFloat)$bottom { return self.frame.origin.y + self.frame.size.height; }
    - (void)set$bottom:(CGFloat)bottom { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=self.frame.size.width, .size.height=MAX(bottom-self.frame.origin.y,0) }; }
    - (void)set$bottom:(CGFloat)bottom { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=self.frame.size.width, .size.height=fmaxf(bottom-self.frame.origin.y,0) }; }

    @end
  2. @nfarina nfarina created this gist Aug 21, 2012.
    10 changes: 10 additions & 0 deletions UIView+FrameAdditions.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    #import <UIKit/UIKit.h>

    @interface UIView (SMFrameAdditions)

    @property (nonatomic, assign) CGPoint $origin;
    @property (nonatomic, assign) CGSize $size;
    @property (nonatomic, assign) CGFloat $x, $y, $width, $height; // normal rect properties
    @property (nonatomic, assign) CGFloat $left, $top, $right, $bottom; // these will stretch the rect

    @end
    35 changes: 35 additions & 0 deletions UIView+FrameAdditions.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #import "UIView+FrameAdditions.h"

    @implementation UIView (SMFrameAdditions)

    - (CGPoint)$origin { return self.frame.origin; }
    - (void)set$origin:(CGPoint)origin { self.frame = (CGRect){ .origin=origin, .size=self.frame.size }; }

    - (CGFloat)$x { return self.frame.origin.x; }
    - (void)set$x:(CGFloat)x { self.frame = (CGRect){ .origin.x=x, .origin.y=self.frame.origin.y, .size=self.frame.size }; }

    - (CGFloat)$y { return self.frame.origin.y; }
    - (void)set$y:(CGFloat)y { self.frame = (CGRect){ .origin.x=self.frame.origin.x, .origin.y=y, .size=self.frame.size }; }

    - (CGSize)$size { return self.frame.size; }
    - (void)set$size:(CGSize)size { self.frame = (CGRect){ .origin=self.frame.origin, .size=size }; }

    - (CGFloat)$width { return self.frame.size.width; }
    - (void)set$width:(CGFloat)width { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=width, .size.height=self.frame.size.height }; }

    - (CGFloat)$height { return self.frame.size.height; }
    - (void)set$height:(CGFloat)height { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=self.frame.size.width, .size.height=height }; }

    - (CGFloat)$left { return self.frame.origin.x; }
    - (void)set$left:(CGFloat)left { self.frame = (CGRect){ .origin.x=left, .origin.y=self.frame.origin.y, .size.width=MAX(self.frame.origin.x+self.frame.size.width-left,0), .size.height=self.frame.size.height }; }

    - (CGFloat)$top { return self.frame.origin.y; }
    - (void)set$top:(CGFloat)top { self.frame = (CGRect){ .origin.x=self.frame.origin.x, .origin.y=top, .size.width=self.frame.size.width, .size.height=MAX(self.frame.origin.y+self.frame.size.height-top,0) }; }

    - (CGFloat)$right { return self.frame.origin.x + self.frame.size.width; }
    - (void)set$right:(CGFloat)right { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=MAX(right-self.frame.origin.x,0), .size.height=self.frame.size.height }; }

    - (CGFloat)$bottom { return self.frame.origin.y + self.frame.size.height; }
    - (void)set$bottom:(CGFloat)bottom { self.frame = (CGRect){ .origin=self.frame.origin, .size.width=self.frame.size.width, .size.height=MAX(bottom-self.frame.origin.y,0) }; }

    @end