Last active
December 18, 2015 02:39
-
-
Save monjer/5712996 to your computer and use it in GitHub Desktop.
UIView+Dimensions.h添加对UIView定位的分类
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Dimensions.h | |
| // | |
| // Created by manjun.han on 12-11-21. | |
| // Copyright (c) 2012年 All rights reserved. | |
| // | |
| #import <UIKit/UIKit.h> | |
| @interface UIView (Dimensions) | |
| @property (nonatomic) CGFloat x ; | |
| @property (nonatomic) CGFloat y ; | |
| @property (nonatomic) CGFloat width ; | |
| @property (nonatomic) CGFloat height ; | |
| @property (nonatomic) CGSize size ; | |
| @property (nonatomic) CGPoint origin ; | |
| // center | |
| @property (nonatomic) CGFloat centerX ; | |
| @property (nonatomic) CGFloat centerY ; | |
| // frame | |
| @property (nonatomic) CGFloat minX ; | |
| @property (nonatomic) CGFloat minY ; | |
| @property (nonatomic) CGFloat midX ; | |
| @property (nonatomic) CGFloat midY ; | |
| @property (nonatomic) CGFloat maxX ; | |
| @property (nonatomic) CGFloat maxY ; | |
| // bounds | |
| @property (nonatomic) CGFloat localMinX ; | |
| @property (nonatomic) CGFloat localMinY ; | |
| @property (nonatomic) CGFloat localMidX ; | |
| @property (nonatomic) CGFloat localMidY ; | |
| @property (nonatomic) CGFloat localMaxX ; | |
| @property (nonatomic) CGFloat localMaxY ; | |
| // local center | |
| @property (nonatomic) CGFloat localCenterX ; | |
| @property (nonatomic) CGFloat localCenterY ; | |
| @property (nonatomic) CGPoint localCenter ; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIView+Dimensions.m | |
| // | |
| // Created by manjun.han on 12-11-21. | |
| // Copyright (c) 2012年 All rights reserved. | |
| // | |
| #import "UIView+Dimensions.h" | |
| @implementation UIView (Dimensions) | |
| @dynamic x , y , width , height ,size ,origin , centerX , centerY , minX , minY , midX , midY , maxX , maxY , | |
| localMaxX,localMaxY,localMidX,localMidY,localMinX,localMinY , localCenterX , localCenterY , localCenter; | |
| //Category中不能添加@synthesize | |
| //@synthesize x = _x ; | |
| -(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)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 ; | |
| } | |
| -(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)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 ; | |
| } | |
| -(CGFloat)minX | |
| { | |
| return CGRectGetMinX(self.frame) ; | |
| } | |
| -(CGFloat)minY | |
| { | |
| return CGRectGetMinY(self.frame) ; | |
| } | |
| -(CGFloat)midX | |
| { | |
| // return self.center.x ; | |
| return CGRectGetMidX(self.frame) ; | |
| } | |
| -(CGFloat)midY | |
| { | |
| // return self.center.y ; | |
| return CGRectGetMidY(self.frame) ; | |
| } | |
| -(CGFloat)maxX | |
| { | |
| return CGRectGetMaxX(self.frame) ; | |
| } | |
| -(CGFloat)maxY | |
| { | |
| return CGRectGetMaxY(self.frame) ; | |
| } | |
| - (CGFloat)localMinX | |
| { | |
| return CGRectGetMinX(self.bounds) ; | |
| } | |
| - (CGFloat)localMinY | |
| { | |
| return CGRectGetMinY(self.bounds) ; | |
| } | |
| - (CGFloat)localMidX | |
| { | |
| return CGRectGetMidX(self.bounds) ; | |
| } | |
| - (CGFloat)localMidY | |
| { | |
| return CGRectGetMidY(self.bounds) ; | |
| } | |
| - (CGFloat)localMaxX | |
| { | |
| return CGRectGetMaxX(self.bounds) ; | |
| } | |
| - (CGFloat)localMaxY | |
| { | |
| return CGRectGetMaxY(self.bounds) ; | |
| } | |
| - (CGFloat)localCenterX | |
| { | |
| return self.localMidX ; | |
| } | |
| - (CGFloat)localCenterY | |
| { | |
| return self.localMidY ; | |
| } | |
| - (CGPoint)localCenter | |
| { | |
| return CGPointMake(self.localCenterX, self.localCenterY) ; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment