Skip to content

Instantly share code, notes, and snippets.

@zhaoyswd
Created August 17, 2013 14:10
Show Gist options
  • Save zhaoyswd/6257039 to your computer and use it in GitHub Desktop.
Save zhaoyswd/6257039 to your computer and use it in GitHub Desktop.
QuickFrame
//
// UIView+ALQuickFrame.h
// ALQuickFrame
//
// Created by Andrea Mario Lufino on 02/07/13.
// Copyright (c) 2013 Andrea Mario Lufino. All rights reserved.
//
// This category is also available as source code
// on github at this link :
// https://github.com/andrealufino/ALQuickFrame
#import <UIKit/UIKit.h>
/*!
* This category allows to access coordinates and size of any view directly
*/
@interface UIView (ALQuickFrame)
/*!
Access the x coordinate
@return The x coordinate of the view
*/
- (CGFloat)x;
/*!
Set the new x coordinate
@param updatedX The new x to set
*/
- (void)setX:(CGFloat)updatedX;
/*!
Access the y coordinate
@return The y coordinate of the view
*/
- (CGFloat)y;
/*!
Set the new y coordinate
@param updatedY The new y to set
*/
- (void)setY:(CGFloat)updatedY;
/*!
Access the width property
@return The width of the view
*/
- (CGFloat)width;
/*!
Set the new width
@param updatedWidth The new width
*/
- (void)setWidth:(CGFloat)updatedWidth;
/*!
The height of the view
@return The height of the view
*/
- (CGFloat)height;
/*!
Set the new height
@param updatedHeight The new height
*/
- (void)setHeight:(CGFloat)updatedHeight;
/*!
The CGSize of the view
@return The size (CGSize) of the view
*/
- (CGSize)size;
/*!
Set the new size
@param updatedSize The new size
*/
- (void)setSize:(CGSize)updatedSize;
@end
//
// UIView+ALQuickFrame.m
// ALQuickFrame
//
// Created by Andrea Mario Lufino on 02/07/13.
// Copyright (c) 2013 Andrea Mario Lufino. All rights reserved.
//
#import "UIView+ALQuickFrame.h"
@implementation UIView (ALQuickFrame)
#pragma mark - X and Y get and set
- (CGFloat)x {
return self.frame.origin.x;
}
- (void)setX:(CGFloat)updatedX {
CGRect frame = self.frame;
frame.origin.x = updatedX;
self.frame = frame;
}
-(CGFloat)y {
return self.frame.origin.y;
}
- (void)setY:(CGFloat)updatedY {
CGRect frame = self.frame;
frame.origin.y = updatedY;
self.frame = frame;
}
- (CGFloat)width {
return self.frame.size.width;
}
#pragma mark - Width and height get and set
-(void)setWidth:(CGFloat)updatedWidth {
CGRect frame = self.frame;
frame.size.width = updatedWidth;
self.frame = frame;
}
-(CGFloat)height {
return self.frame.size.height;
}
-(void)setHeight:(CGFloat)updatedHeight {
CGRect frame = self.frame;
frame.size.height = updatedHeight;
self.frame = frame;
}
#pragma mark - Size get and set
-(CGSize)size {
return self.frame.size;
}
-(void)setSize:(CGSize)updatedSize {
CGRect frame = self.frame;
frame.size = updatedSize;
self.frame = frame;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment