大家可以去我的Githup下载 https://github.com/simplyou/YJ-UIIView-/tree/master
在设置尺寸的时候亲们有没有感觉很蛋疼啊,这里提供了一套分类,直接放进工程里,在PCH中包含头文件就能解决你蛋疼的问题;
/*********************** .h文件 ********************************
// UIView+YJ.h
// Created by 闪电 on 14-6-8.
// Copyright (c) 2014年 温艳军. All rights reserved.
// 这分类是为了解决在OC中设置宽高的问题,提供了一种快捷的方法
#import <UIKit/UIKit.h>
@interface UIView (YJ)
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) CGFloat centerX;
@property (nonatomic, assign) CGFloat centerY;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) CGSize size;
@end
/*****************************华丽分割线**********************
************************ .m文件 **********************************
// UIView+YJ.h
// Created by 闪电 on 14-6-8.
// Copyright (c) 2014年 温艳军. All rights reserved.
// 这分类是为了解决在OC中设置宽高的问题,提供了一种快捷的方法
#import "UIView+YJ.h"
@implementation UIView (YJ)
- (void)setSize:(CGSize)size
{
CGRect frame = self.frame;
frame.size = size;
self.frame = frame;
}
- (CGSize)size
{
return self.frame.size;
}
- (void)setX:(CGFloat)x
{
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}
- (CGFloat)x
{
return self.frame.origin.x;
}
- (void)setY:(CGFloat)y
{
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}
- (CGFloat)y
{
return self.frame.origin.y;
}
- (void)setCenterX:(CGFloat)centerX
{
CGPoint center = self.center;
center.x = centerX;
self.center = center;
}
- (CGFloat)centerX
{
return self.center.x;
}
- (void)setCenterY:(CGFloat)centerY
{
CGPoint center = self.center;
center.y = centerY;
self.center = center;
}
- (CGFloat)centerY
{
return self.center.y;
}
- (void)setWidth:(CGFloat)width
{
CGRect frame = self.frame;
frame.size.width = width;
self.frame = frame;
}
- (CGFloat)width
{
return self.frame.size.width;
}
- (void)setHeight:(CGFloat)height
{
CGRect frame = self.frame;
frame.size.height = height;
self.frame = frame;
}
- (CGFloat)height
{
return self.frame.size.height;
}
@end
IOS设置frame的时候经常要先取出来-> 设置-> 最后再赋值回去,非常麻烦,今天给大家推荐一种非常快捷的方法,布布扣,bubuko.com