码迷,mamicode.com
首页 > 其他好文 > 详细

UIView+Category

时间:2016-01-28 12:19:43      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

1  .h

#import <UIKit/UIKit.h>

 

@interface UIView (UIView_Category)

@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;

@property (nonatomic, assign) CGPoint origin;

@property (nonatomic, assign) CGFloat minX;

@property (nonatomic, assign) CGFloat minY;

@property (nonatomic, assign) CGFloat maxX;

@property (nonatomic, assign) CGFloat maxY;

 

-(void)setMaskRadius:(float)radius;

@end

2  .m

#import "UIView+Category.h"

 

@implementation UIView (UIView_Category)

 

- (void)setX:(CGFloat)x

{

    CGRect frame = self.frame;

    frame.origin.x = x;

    self.frame = frame;

}

 

- (void)setY:(CGFloat)y

{

    CGRect frame = self.frame;

    frame.origin.y = y;

    self.frame = frame;

}

 

- (CGFloat)x

{

    return self.frame.origin.x;

}

 

- (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;

}

 

- (void)setHeight:(CGFloat)height

{

    CGRect frame = self.frame;

    frame.size.height = height;

    self.frame = frame;

}

 

- (CGFloat)height

{

    return self.frame.size.height;

}

 

- (CGFloat)width

{

    return self.frame.size.width;

}

 

- (void)setSize:(CGSize)size

{

    CGRect frame = self.frame;

    frame.size = size;

    self.frame = frame;

}

 

- (CGSize)size

{

    return self.frame.size;

}

 

- (void)setOrigin:(CGPoint)origin

{

    CGRect frame = self.frame;

    frame.origin = origin;

    self.frame = frame;

}

 

- (CGPoint)origin

{

    return self.frame.origin;

}

 

- (void)setMinX:(CGFloat)minX{

    self.minX = self.x;

}

 

- (CGFloat)minX{

    return CGRectGetMinX(self.frame);

}

 

- (void)setMinY:(CGFloat)minY{

    self.maxY = self.y;

}

 

- (CGFloat)minY{

    return CGRectGetMinY(self.frame);

}

 

- (void)setMaxX:(CGFloat)maxX{

    self.maxX = self.x +self.width;

}

 

- (CGFloat)maxX{

    return CGRectGetMaxX(self.frame);

}

 

- (void)setMaxY:(CGFloat)maxY{

    self.maxY = self.y + self.height;

}

 

- (CGFloat)maxY{

    return CGRectGetMaxY(self.frame);

}

 

-(void)setMaskRadius:(float)radius{

    self.layer.masksToBounds = YES;

    self.layer.cornerRadius = radius;

}

@end

 

 

UIView+Category

标签:

原文地址:http://www.cnblogs.com/heiheihei/p/5165629.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!