Last active
August 29, 2015 14:03
-
-
Save dnnta/a2f4e4d8ef590edb067e to your computer and use it in GitHub Desktop.
UIView Frame Category
This file contains 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
// | |
// UIView+Frame.h | |
// | |
// | |
// Created by xxxx on 14-5-28. | |
// Copyright (c) 2014年 TBJ. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIView (Frame) | |
- (CGPoint)origin; | |
- (void)setOrigin:(CGPoint)origin; | |
- (CGSize)size; | |
- (void)setSize:(CGSize)size; | |
- (CGFloat)x; | |
- (void)setX:(CGFloat)x; | |
- (CGFloat)y; | |
- (void)setY:(CGFloat)y; | |
- (CGFloat)width; | |
- (void)setWidth:(CGFloat)width; | |
- (CGFloat)height; | |
- (void)setHeight:(CGFloat)height; | |
- (CGFloat)bottom; | |
- (void)setBottom:(CGFloat)bottom; | |
- (CGFloat)right; | |
- (void)setRight:(CGFloat)right; | |
@end |
This file contains 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
// | |
// UIView+Frame.m | |
// | |
// | |
// Created by on 14-5-28. | |
// Copyright (c) 2014年 TBJ. All rights reserved. | |
// | |
#import "UIView+Frame.h" | |
@implementation UIView (Frame) | |
- (CGPoint)origin | |
{ | |
return self.frame.origin; | |
} | |
- (void)setOrigin:(CGPoint)origin | |
{ | |
self.frame = CGRectMake(origin.x, origin.y, self.frame.size.width, self.frame.size.height); | |
} | |
- (CGSize)size | |
{ | |
return self.frame.size; | |
} | |
- (void)setSize:(CGSize)size | |
{ | |
self.frame = CGRectMake(self.x, self.y, size.width, size.height); | |
} | |
- (CGFloat)x | |
{ | |
return self.frame.origin.x; | |
} | |
- (void)setX:(CGFloat)x | |
{ | |
self.frame = CGRectMake(x, self.y, self.width, self.height); | |
} | |
- (CGFloat)y | |
{ | |
return self.frame.origin.y; | |
} | |
- (void)setY:(CGFloat)y | |
{ | |
self.frame = CGRectMake(self.x, y, self.width, self.width); | |
} | |
- (CGFloat)width | |
{ | |
return self.frame.size.width; | |
} | |
- (void)setWidth:(CGFloat)width | |
{ | |
self.frame = CGRectMake(self.x, self.y, width, self.height); | |
} | |
- (CGFloat)height | |
{ | |
return self.frame.size.height; | |
} | |
- (void)setHeight:(CGFloat)height | |
{ | |
self.frame = CGRectMake(self.x, self.y, self.width, height); | |
} | |
- (CGFloat)bottom | |
{ | |
return CGRectGetMaxY(self.frame); | |
} | |
- (void)setBottom:(CGFloat)bottom | |
{ | |
self.frame = CGRectMake(self.x, bottom - self.width, self.width, self.height); | |
} | |
- (CGFloat)right | |
{ | |
return CGRectGetMaxX(self.frame); | |
} | |
- (void)setRight:(CGFloat)right | |
{ | |
self.frame = CGRectMake(right-self.width, self.y, self.width, self.height); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment