首页 > 移动平台 > 详细

UIView的分类--iOS

时间:2016-09-09 00:29:45      阅读:203      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!