Created
December 25, 2012 17:28
-
-
Save ginrou/4374294 to your computer and use it in GitHub Desktop.
UIViewでtopとかrightとかで指定できるようにした拡張
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
#import <UIKit/UIKit.h> | |
@interface UIView (frame) | |
@property (nonatomic, assign) CGPoint origin; | |
@property (nonatomic, assign) CGFloat left; | |
@property (nonatomic, assign) CGFloat right; | |
@property (nonatomic, assign) CGFloat top; | |
@property (nonatomic, assign) CGFloat bottom; | |
@property (nonatomic, assign) CGSize size; | |
@property (nonatomic, assign) CGFloat width; | |
@property (nonatomic, assign) CGFloat height; | |
@property (nonatomic, assign) CGPoint center; | |
@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
#import "UIView+frame.h" | |
@implementation UIView (frame) | |
- (CGPoint)origin | |
{ | |
return self.origin; | |
} | |
- (void)setOrigin:(CGPoint)origin | |
{ | |
CGRect frame = self.frame; | |
frame.origin = origin; | |
self.frame = frame; | |
} | |
- (CGFloat)left | |
{ | |
return self.frame.origin.x; | |
} | |
- (void)setLeft:(CGFloat)left | |
{ | |
CGRect frame = self.frame; | |
frame.origin.x = left; | |
self.frame = frame; | |
} | |
- (CGFloat)right | |
{ | |
return self.frame.origin.x + self.frame.size.width; | |
} | |
- (void)setRight:(CGFloat)right | |
{ | |
CGRect frame = self.frame; | |
frame.origin.x = right - frame.size.width; | |
self.frame = frame; | |
} | |
- (CGFloat)top | |
{ | |
return self.frame.origin.y; | |
} | |
- (void)setTop:(CGFloat)top | |
{ | |
CGRect frame = self.frame; | |
frame.origin.y = top; | |
self.frame = frame; | |
} | |
- (CGFloat)bottom | |
{ | |
return self.frame.origin.y + self.frame.size.height; | |
} | |
- (void)setBottom:(CGFloat)bottom | |
{ | |
CGRect frame = self.frame; | |
frame.origin.y = bottom - self.frame.size.height; | |
self.frame = frame; | |
} | |
- (CGSize)size | |
{ | |
return self.frame.size; | |
} | |
- (void)setSize:(CGSize)size | |
{ | |
CGRect frame = self.frame; | |
frame.size = size; | |
self.frame = frame; | |
} | |
- (CGFloat)width | |
{ | |
return self.frame.size.width; | |
} | |
- (void)setWidth:(CGFloat)width | |
{ | |
CGRect frame = self.frame; | |
frame.size.width = width; | |
self.frame = frame; | |
} | |
- (CGFloat)height | |
{ | |
return self.frame.size.height; | |
} | |
- (void)setHeight:(CGFloat)height | |
{ | |
CGRect frame = self.frame; | |
frame.size.height = height; | |
self.frame = frame; | |
} | |
- (CGPoint)center | |
{ | |
return CGPointMake(self.left + self.width/2.0, self.top + self.height / 2.0 ); | |
} | |
- (void)setCenter:(CGPoint)center | |
{ | |
CGRect frame = self.frame; | |
frame.origin.x = center.x - frame.size.width / 2.0; | |
frame.origin.y = center.y - frame.size.height / 2.0; | |
self.frame = frame; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import "UIView+frame.h"をすれば使えます。