|
//
// UIView+EasyExtend.m
// leway
//
// Created by 朱潮 on 14-6-5.
// Copyright (c) 2014年 zhuchao. All rights reserved.
//
#import "UIView+EasyExtend.h"
@implementation UIView (EasyExtend)
#pragma mark - Location
- (CGPoint)origin
{
return self.frame.origin;
}
- (void)setOrigin:(CGPoint)origin
{
CGRect newframe = self.frame;
newframe.origin = origin;
self.frame = newframe;
}
- (CGFloat)top
{
return self.frame.origin.y;
}
- (void)setTop:(CGFloat)top
{
CGRect newframe = self.frame;
newframe.origin.y = top;
self.frame = newframe;
}
- (CGFloat)left
{
return self.frame.origin.x;
}
- (void)setLeft:(CGFloat)left
{
CGRect newframe = self.frame;
newframe.origin.x = left;
self.frame = newframe;
}
- (CGFloat)bottom
{
return self.frame.origin.y + self.frame.size.height;
}
- (void)setBottom: (CGFloat)bottom
{
CGRect newframe = self.frame;
newframe.origin.y = bottom - self.frame.size.height;
self.frame = newframe;
}
- (CGFloat)right
{
return self.frame.origin.x + self.frame.size.width;
}
- (void)setRight:(CGFloat)right
{
CGRect newframe = self.frame;
newframe.origin.x = right - self.frame.size.width;
self.frame = newframe;
}
#pragma mark - Center
- (CGFloat)centerX
{
return self.center.x;
}
- (void)setCenterX:(CGFloat)centerX
{
CGPoint newCenter = self.center;
newCenter.x = centerX;
self.center = newCenter;
}
- (CGFloat)centerY
{
return self.center.y;
}
- (void)setCenterY:(CGFloat)centerY
{
CGPoint newCenter = self.center;
newCenter.y = centerY;
self.center = newCenter;
}
#pragma mark - Size
- (CGSize)size
{
return self.frame.size;
}
- (void)setSize:(CGSize)size
{
CGRect newframe = self.frame;
newframe.size = size;
self.frame = newframe;
}
- (CGFloat)height
{
return self.frame.size.height;
}
- (void)setHeight:(CGFloat)height
{
CGRect newframe = self.frame;
newframe.size.height = height;
self.frame = newframe;
}
- (CGFloat)width
{
return self.frame.size.width;
}
- (void)setWidth:(CGFloat)width
{
CGRect newframe = self.frame;
newframe.size.width = width;
self.frame = newframe;
}
#pragma mark - Other Origin
- (CGPoint)bottomRight
{
CGFloat x = self.frame.origin.x + self.frame.size.width;
CGFloat y = self.frame.origin.y + self.frame.size.height;
return CGPointMake(x, y);
}
- (CGPoint)bottomLeft
{
CGFloat x = self.frame.origin.x;
CGFloat y = self.frame.origin.y + self.frame.size.height;
return CGPointMake(x, y);
}
- (CGPoint)topRight
{
CGFloat x = self.frame.origin.x + self.frame.size.width;
CGFloat y = self.frame.origin.y;
return CGPointMake(x, y);
}
- (UIImage *)saveImageWithScale:(float)scale
{
UIGraphicsBeginImageContextWithOptions(self.frame.size, NO, scale);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
|