Created
June 27, 2014 03:19
-
-
Save hiromitsu-murakami/ed332c3ff96cf41c53b3 to your computer and use it in GitHub Desktop.
UIView+BOX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
// Shortcut of frame rect | |
@interface UIView (BOX) | |
@property (nonatomic, assign) CGFloat box_x; | |
@property (nonatomic, assign) CGFloat box_y; | |
@property (nonatomic, assign) CGFloat box_width; | |
@property (nonatomic, assign) CGFloat box_height; | |
@property (nonatomic, assign) CGFloat box_centerX; | |
@property (nonatomic, assign) CGFloat box_centerY; | |
@property (nonatomic, assign) CGFloat box_top; | |
@property (nonatomic, assign) CGFloat box_right; | |
@property (nonatomic, assign) CGFloat box_bottom; | |
@property (nonatomic, assign) CGFloat box_left; | |
@property (nonatomic, assign, readonly) CGFloat box_halfWidth; | |
@property (nonatomic, assign, readonly) CGFloat box_halfHeight; | |
@property (nonatomic, assign) CGPoint box_origin; | |
@property (nonatomic, assign) CGSize box_size; | |
// Origin | |
- (void)box_x:(CGFloat)x | |
y:(CGFloat)y; | |
// Size | |
- (void)box_width:(CGFloat)width | |
height:(CGFloat)height; | |
// Frame | |
- (void)box_x:(CGFloat)x | |
y:(CGFloat)y | |
width:(CGFloat)width | |
height:(CGFloat)height; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UIView+BOX.h" | |
@implementation UIView (BOX) | |
- (CGFloat)box_x { return self.frame.origin.x; } | |
- (CGFloat)box_y { return self.frame.origin.y; } | |
- (CGFloat)box_width { return self.frame.size.width; } | |
- (CGFloat)box_height { return self.frame.size.height; } | |
- (void)setBox_x:(CGFloat)x { [self box_x:x y:self.box_y ]; } | |
- (void)setBox_y:(CGFloat)y { [self box_x:self.box_x y:y ]; } | |
- (void)setBox_width:(CGFloat)width { [self box_width:width height:self.box_height]; } | |
- (void)setBox_height:(CGFloat)height { [self box_width:self.box_width height:height ]; } | |
- (CGFloat)box_centerX { return self.center.x; } | |
- (CGFloat)box_centerY { return self.center.y; } | |
- (void)setBox_centerX:(CGFloat)centerX { self.center = CGPointMake(centerX, self.center.y); } | |
- (void)setBox_centerY:(CGFloat)centerY { self.center = CGPointMake(self.center.x, centerY); } | |
- (CGFloat)box_top { return self.box_y; } | |
- (CGFloat)box_right { return self.box_x + self.box_width; } | |
- (CGFloat)box_bottom { return self.box_y + self.box_height; } | |
- (CGFloat)box_left { return self.box_x; } | |
- (void)setBox_top:(CGFloat)y { self.box_y = y; } | |
- (void)setBox_right:(CGFloat)right { self.box_x = right - self.box_width; } | |
- (void)setBox_bottom:(CGFloat)bottom { self.box_y = bottom - self.box_height; } | |
- (void)setBox_left:(CGFloat)x { self.box_x = x; } | |
- (CGFloat)box_halfWidth { return self.box_width / 2.0; } | |
- (CGFloat)box_halfHeight { return self.box_height / 2.0; } | |
- (CGPoint)box_origin { return self.frame.origin; } | |
- (CGSize)box_size { return self.frame.size; } | |
- (void)setBox_origin:(CGPoint)origin { [self box_x:origin.x y:origin.y ]; } | |
- (void)setBox_size:(CGSize)size { [self box_width:size.width height:size.height]; } | |
// Origin | |
- (void)box_x:(CGFloat)x | |
y:(CGFloat)y | |
{ | |
[self box_x:x | |
y:y | |
width:self.box_width | |
height:self.box_height]; | |
} | |
// Size | |
- (void)box_width:(CGFloat)width | |
height:(CGFloat)height | |
{ | |
[self box_x:self.box_x | |
y:self.box_y | |
width:width | |
height:height]; | |
} | |
// Frame | |
- (void)box_x:(CGFloat)x | |
y:(CGFloat)y | |
width:(CGFloat)width | |
height:(CGFloat)height | |
{ | |
self.frame = CGRectMake(x, y, width, height); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment