码迷,mamicode.com
首页 > 移动开发 > 详细

UIView的分类--iOS

时间:2016-09-09 00:32:20      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:

#import <UIKit/UIKit.h>

 

@interface UIView (PJXExtension)

@property(assign,nonatomic) CGFloat x; //x坐标

@property(assign,nonatomic) CGFloat y; //y坐标

@property(assign,nonatomic) CGFloat width; //宽度

@property(assign,nonatomic) CGFloat height; //高度

@property(assign,nonatomic) CGFloat centerX; //中心点X值

@property(assign,nonatomic) CGFloat centerY; //中心点Y值

 

@end

 

#import "UIView+PJXExtension.h"

 

@implementation UIView (PJXExtension)

//x

-(void)setX:(CGFloat)x{

    CGRect frame = self.frame;

    frame.origin.x = x;

    self.frame = frame;

}

-(CGFloat)x{

    return self.frame.origin.x;

}

 

//y

-(void)setY:(CGFloat)y{

    CGRect frame = self.frame;

    frame.origin.y = y;

    self.frame = frame;

}

-(CGFloat)y{

    return self.frame.origin.y;

}

 

 

//width

-(void)setWidth:(CGFloat)width{

    CGRect frame = self.frame;

    frame.size.width = width;

    self.frame = frame;

}

-(CGFloat)width{

    return self.frame.size.width;

}

 

//height

-(void)setHeight:(CGFloat)height{

    CGRect frame = self.frame;

    frame.size.height = height;

    self.frame = frame;

}

-(CGFloat)height{

    return self.frame.size.height;

}

 

//centerX

-(void)setCenterX:(CGFloat)centerX{

    CGRect frame = self.frame;

    frame.origin.x = centerX - frame.size.width/2.0;

    self.frame = frame;

}

-(CGFloat)centerX{

    return CGRectGetMidX(self.frame);

}

 

//centerY

-(void)setCenterY:(CGFloat)centerY{

    CGRect frame = self.frame;

    frame.origin.y = centerY - frame.size.height/2.0;

    self.frame = frame;

}

-(CGFloat)centerY{

    return CGRectGetMidY(self.frame);

}

/*

 //中心X

 -(CGFloat)centerX

 {

 return  self.center.x;

 }

 

 -(void)setCenterX:(CGFloat)centerX

 {

 CGPoint center = self.center;

 center.x = centerX;

 self.center = center;

 }

 

 //中心点Y

 -(CGFloat)centerY

 {

 return  self.center.y;

 }

 

 -(void)setCenterY:(CGFloat)centerY

 {

 CGPoint center = self.center;

 center.y = centerY;

 self.center = center;

 }

 

 

 

 */

@end

 

UIView的分类--iOS

标签:

原文地址:http://www.cnblogs.com/PJXWang/p/5854811.html

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