美文网首页
UIView +frame

UIView +frame

作者: BeSt2wazi | 来源:发表于2017-07-13 17:23 被阅读0次
    #import <UIKit/UIKit.h>
    
    @interface UIView (BGFrame)
    
    //不用再蛋疼的写某view.frame=CGRectMake(x,y,z,o)了。
    - (CGFloat)left;
    - (CGFloat)right;
    - (CGSize)size;
    - (CGFloat)top;
    - (CGFloat)bottom;
    - (CGFloat)width;
    - (CGFloat)height;
    - (CGFloat)centerX;
    - (CGFloat)centerY;
    - (CGFloat)maxX;
    - (CGFloat)maxY;
    - (void)setLeft:(CGFloat)left;
    - (void)setRight:(CGFloat)right;
    - (void)setSize:(CGSize)size;
    - (void)setTop:(CGFloat)top;
    - (void)setBottom:(CGFloat)bottom;
    - (void)setWidth:(CGFloat)width;
    - (void)setHeight:(CGFloat)height;
    - (void)setCenterX:(CGFloat)centerX;
    - (void)setCenterY:(CGFloat)centerY;
    - (void)setOrigin:(CGPoint)point;
    - (void)setAddTop:(CGFloat)top;
    - (void)setAddLeft:(CGFloat)left;
    
    @end
    
    #import "UIView+BGFrame.h"
    
    @implementation UIView (BGFrame)
    
    - (CGFloat)left
    {
        return self.frame.origin.x;
    }
    
    - (CGFloat)right
    {
        return self.frame.origin.x + self.frame.size.width;
    }
    
    - (CGFloat)top
    {
        return self.frame.origin.y;
    }
    
    - (CGFloat)bottom
    {
        return self.frame.origin.y + self.frame.size.height;
    }
    
    - (CGSize)size{
        return self.frame.size;
    }
    
    - (CGFloat)width
    {
        return self.frame.size.width;
    }
    
    - (CGFloat)height
    {
        return self.frame.size.height;
    }
    
    - (CGFloat)centerX
    {
        return self.center.x;
    }
    
    - (CGFloat)centerY
    {
        return self.center.y;
    }
    
    - (CGFloat)maxX
    {
        return CGRectGetMaxX(self.frame);
    }
    
    - (CGFloat)maxY
    {
        return CGRectGetMaxY(self.frame);
    }
    
    - (void)setLeft:(CGFloat)left
    {
        CGRect frame = self.frame;
        frame.origin.x = left;
        self.frame = frame;
    }
    
    - (void)setRight:(CGFloat)right;
    {
        CGRect frame = self.frame;
        frame.origin.x = right - frame.size.width;
        self.frame = frame;
    }
    
    - (void)setBottom:(CGFloat)bottom
    {
        CGRect frame = self.frame;
        frame.origin.y = bottom - frame.size.height;
        self.frame = frame;
    }
    
    - (void)setSize:(CGSize)size
    {
        CGRect frame = self.frame;
        frame.size = size;
        self.frame = frame;
    }
    
    - (void)setTop:(CGFloat)top
    {
        CGRect frame = self.frame;
        frame.origin.y = top;
        self.frame = frame;
    }
    
    - (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;
    }
    
    - (void)setOrigin:(CGPoint)point
    {
        CGRect frame = self.frame;
        frame.origin = point;
        self.frame = frame;
    }
    
    - (void)setCenterX:(CGFloat)centerX
    {
        self.center = CGPointMake(centerX, self.center.y);
    }
    
    - (void)setCenterY:(CGFloat)centerY
    {
        self.center = CGPointMake(self.center.x, centerY);
    }
    
    - (void)setAddTop:(CGFloat)top
    {
        CGRect frame = self.frame;
        frame.origin.y += top;
        self.frame = frame;
    }
    
    - (void)setAddLeft:(CGFloat)left
    {
        CGRect frame = self.frame;
        frame.origin.x += left;
        self.frame = frame;
    }
    
    @end
    

    相关文章

      网友评论

          本文标题:UIView +frame

          本文链接:https://www.haomeiwen.com/subject/hofghxtx.html