@interface UIView (extend) aView.frame = CGRectMake(aView.frame.origin.x, aView.frame.origin.y, 100, aView.frame.size.height); @endって書くのまんどくせー。
ってことで下記のようなUIViewの拡張メソッドを用意して使っています。
@interface UIView (extend) - (void)setX:(NSInteger)x; - (void)setY:(NSInteger)y; - (void)setWidth:(NSInteger)width; - (void)setHeight:(NSInteger)height; - (void)setOrigin:(CGPoint)point; - (void)setSize:(CGSize)size; @end
#import "UIView+extend.h" @implementation UIView (extend) - (void)setX:(NSInteger)x { self.frame = CGRectMake( x, self.frame.origin.y, self.frame.size.width, self.frame.size.height ); } - (void)setY(NSInteger)y { self.frame = CGRectMake( self.frame.origin.x, y, self.frame.size.width, self.frame.size.height ); } - (void)setWidth:(NSInteger)width { self.frame = CGRectMake( self.frame.origin.x, self.frame.origin.y, self, view.frame.size.height ); } - (void)setHeight:(NSInteger)height { self.frame = CGRectMake( view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height ); } - (void)setOrigin:(CGPoint)point { self.frame = CGRectMake(point.x, point.y, self.frame.size.width, self.frame.size.height); } - (void)setSize:(CGSize)size { self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, size.width, size.height); } - (void)setViewSizeHalf:(UIView*)view { view.frame = CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width/2, view.frame.size.height/2); } @end
#import "Hoge.h" #import "UIView+extend.h" @implementation Hoge - (id)init { if (self = [super init]) { UIView *aView = [[[UIView alloc] init] autorelease]; [aView setX:100]; } return self; } @end実績の無いソースコードなのでコピペじゃコンパイル通らないかもしれません。 ツイート
0 件のコメント :
コメントを投稿