.h文件
#import <UIKit/UIKit.h>
/**
* UIScreen width.
*/
#define CLscreenWidth [UIScreen mainScreen].bounds.size.width
/**
* UIScreen height.
*/
#define CLscreenHeight [UIScreen mainScreen].bounds.size.height
/**iPhone5为标准,乘以宽的比例*/
#define CLscaleX(value) (((value) / 2.0f)/320.0f * CLscreenWidth)
/**iPhone5为标准,乘以高的比例*/
#define CLscaleY(value) (((value) / 2.0f)/568.0f * CLscreenHeight)
/**
* Status bar height.
*/
#define CLstatusBarHeight 20.f
/**
* Navigation bar height.
*/
#define CLnavigationBarHeight 44.f
/**
* Tabbar height.
*/
#define CLtabbarHeight 49.f
/**
* Status bar & navigation bar height.
*/
#define CLstatusBarAndNavigationBarHeight (20.f + 44.f)
/**
* iPhone4 or iPhone4s
*/
#define iPhone4_4s (Width == 320.f && Height == 480.f ? YES : NO)
/**
* iPhone5 or iPhone5s
*/
#define iPhone5_5s (Width == 320.f && Height == 568.f ? YES : NO)
/**
* iPhone6 or iPhone6s
*/
#define iPhone6_6s (Width == 375.f && Height == 667.f ? YES : NO)
/**
* iPhone6Plus or iPhone6sPlus
*/
#define iPhone6_6sPlus (Width == 414.f && Height == 736.f ? YES : NO)
@interface UIView (CLSetRect)
/**
控件起点
*/
@property (nonatomic) CGPoint CLviewOrigin;
/**
控件大小
*/
@property (nonatomic) CGSize CLviewSize;
/**
控件起点x
*/
@property (nonatomic) CGFloat CLx;
/**
控件起点Y
*/
@property (nonatomic) CGFloat CLy;
/**
控件宽
*/
@property (nonatomic) CGFloat CLwidth;
/**
控件高
*/
@property (nonatomic) CGFloat CLheight;
/**
控件顶部
*/
@property (nonatomic) CGFloat CLtop;
/**
控件底部
*/
@property (nonatomic) CGFloat CLbottom;
/**
控件左边
*/
@property (nonatomic) CGFloat CLleft;
/**
控件右边
*/
@property (nonatomic) CGFloat CLright;
/**
控件中心点X
*/
@property (nonatomic) CGFloat CLcenterX;
/**
控件中心点Y
*/
@property (nonatomic) CGFloat CLcenterY;
/**
控件左下
*/
@property(readonly) CGPoint CLbottomLeft ;
/**
控件右下
*/
@property(readonly) CGPoint CLbottomRight ;
/**
控件左上
*/
@property(readonly) CGPoint CLtopLeft ;
/**
控件右上
*/
@property(readonly) CGPoint CLtopRight ;
/**
屏幕中心点X
*/
@property (nonatomic, readonly) CGFloat CLmiddleX;
/**
屏幕中心点Y
*/
@property (nonatomic, readonly) CGFloat CLmiddleY;
/**
屏幕中心点
*/
@property (nonatomic, readonly) CGPoint CLmiddlePoint;
/**
设置上边圆角
*/
- (void)setCornerOnTop:(CGFloat) conner;
/**
设置下边圆角
*/
- (void)setCornerOnBottom:(CGFloat) conner;
/**
设置左边圆角
*/
- (void)setCornerOnLeft:(CGFloat) conner;
/**
设置右边圆角
*/
- (void)setCornerOnRight:(CGFloat) conner;
/**
设置左上圆角
*/
- (void)setCornerOnTopLeft:(CGFloat) conner;
/**
设置右上圆角
*/
- (void)setCornerOnTopRight:(CGFloat) conner;
/**
设置左下圆角
*/
- (void)setCornerOnBottomLeft:(CGFloat) conner;
/**
设置右下圆角
*/
- (void)setCornerOnBottomRight:(CGFloat) conner;
/**
设置所有圆角
*/
- (void)setAllCorner:(CGFloat) conner;
/**
设置下方以及右上圆角
*/
- (void)setRightAndBottonCorner:(CGFloat) conner;
@end
.m文件
#import "UIView+CLSetRect.h"
@implementation UIView (CLSetRect)
- (CGPoint)CLviewOrigin {
return self.frame.origin;
}
- (void)setCLviewOrigin:(CGPoint)CLviewOrigin {
CGRect newFrame = self.frame;
newFrame.origin = CLviewOrigin;
self.frame = newFrame;
}
- (CGSize)CLviewSize {
return self.frame.size;
}
- (void)setCLviewSize:(CGSize)CLviewSize {
CGRect newFrame = self.frame;
newFrame.size = CLviewSize;
self.frame = newFrame;
}
- (CGFloat)CLx {
return self.frame.origin.x;
}
- (void)setCLx:(CGFloat)CLx {
CGRect newFrame = self.frame;
newFrame.origin.x = CLx;
self.frame = newFrame;
}
- (CGFloat)CLy {
return self.frame.origin.y;
}
- (void)setCLy:(CGFloat)CLy {
CGRect newFrame = self.frame;
newFrame.origin.y = CLy;
self.frame = newFrame;
}
- (CGFloat)CLwidth {
return CGRectGetWidth(self.bounds);
}
- (void)setCLwidth:(CGFloat)CLwidth {
CGRect newFrame = self.frame;
newFrame.size.width = CLwidth;
self.frame = newFrame;
}
- (CGFloat)CLheight {
return CGRectGetHeight(self.bounds);
}
- (void)setCLheight:(CGFloat)CLheight {
CGRect newFrame = self.frame;
newFrame.size.height = CLheight;
self.frame = newFrame;
}
- (CGFloat)CLtop {
return self.frame.origin.y;
}
- (void)setCLtop:(CGFloat)CLtop {
CGRect newFrame = self.frame;
newFrame.origin.y = CLtop;
self.frame = newFrame;
}
- (CGFloat)CLbottom {
return self.frame.origin.y + self.frame.size.height;
}
- (void)setCLbottom:(CGFloat)CLbottom {
CGRect newFrame = self.frame;
newFrame.origin.y = CLbottom - self.frame.size.height;
self.frame = newFrame;
}
- (CGFloat)CLleft {
return self.frame.origin.x;
}
- (void)setCLleft:(CGFloat)CLleft {
CGRect newFrame = self.frame;
newFrame.origin.x = CLleft;
self.frame = newFrame;
}
- (CGFloat)CLright {
return self.frame.origin.x + self.frame.size.width;
}
- (void)setCLright:(CGFloat)CLright {
CGRect newFrame = self.frame;
newFrame.origin.x = CLright - self.frame.size.width;
self.frame = newFrame;
}
- (CGFloat)CLcenterX {
return self.center.x;
}
- (void)setCLcenterX:(CGFloat)CLcenterX {
CGPoint newCenter = self.center;
newCenter.x = CLcenterX;
self.center = newCenter;
}
- (CGFloat)CLcenterY {
return self.center.y;
}
- (void)setCLcenterY:(CGFloat)CLcenterY {
CGPoint newCenter = self.center;
newCenter.y = CLcenterY;
self.center = newCenter;
}
- (CGPoint)CLbottomRight
{
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)CLbottomLeft
{
CGFloat x = self.frame.origin.x;
CGFloat y = self.frame.origin.y + self.frame.size.height;
return CGPointMake(x, y);
}
- (CGPoint)CLtopRight
{
CGFloat x = self.frame.origin.x + self.frame.size.width;
CGFloat y = self.frame.origin.y;
return CGPointMake(x, y);
}
- (CGPoint)CLtopLeft
{
CGFloat x = self.frame.origin.x;
CGFloat y = self.frame.origin.y;
return CGPointMake(x, y);
}
- (CGFloat)CLmiddleX {
return CGRectGetWidth(self.bounds) / 2.f;
}
- (CGFloat)CLmiddleY {
return CGRectGetHeight(self.bounds) / 2.f;
}
- (CGPoint)CLmiddlePoint {
return CGPointMake(CGRectGetWidth(self.bounds) / 2.f, CGRectGetHeight(self.bounds) / 2.f);
}
#pragma mark - 设置圆角
- (void)setCornerOnTop:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnBottom:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnLeft:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnRight:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnTopLeft:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopLeft
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnTopRight:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopRight
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setRightAndBottonCorner:(CGFloat) conner{
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnBottomLeft:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerBottomLeft
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnBottomRight:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(conner, conner)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setAllCorner:(CGFloat) conner {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
cornerRadius:conner];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
@end