Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple but really useful category on UIView that makes modifying the frame NOT hellish. Published under WTFPL [http://www.wtfpl.net/]. Usage example can be found in the comments
/*
Before:
CGRect frame = myView.frame;
frame.origin.x = newX;
myView.frame = frame;
After:
myView.x = newX;
*/
#import <UIKit/UIKit.h>
@interface UIView (Ext)
@property float x;
@property float y;
@property float width;
@property float height;
@end
#import "UIView+Ext.h"
@implementation UIView (Ext)
-(float) x {
return self.frame.origin.x;
}
-(void) setX:(float) newX {
CGRect frame = self.frame;
frame.origin.x = newX;
self.frame = frame;
}
-(float) y {
return self.frame.origin.y;
}
-(void) setY:(float) newY {
CGRect frame = self.frame;
frame.origin.y = newY;
self.frame = frame;
}
-(float) width {
return self.frame.size.width;
}
-(void) setWidth:(float) newWidth {
CGRect frame = self.frame;
frame.size.width = newWidth;
self.frame = frame;
}
-(float) height {
return self.frame.size.height;
}
-(void) setHeight:(float) newHeight {
CGRect frame = self.frame;
frame.size.height = newHeight;
self.frame = frame;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment