iOS UIView分类

作者: 72行代码 | 来源:发表于2019-10-23 17:32 被阅读0次
    1. .h内容
    - (CGPoint)origin;
    - (void)setOrigin:(CGPoint)point;
    
    - (CGSize)size;
    - (void)setSize:(CGSize)size;
    
    - (CGFloat)x;
    - (void)setX:(CGFloat)x;
    
    - (CGFloat)y;
    - (void)setY:(CGFloat)y;
    
    - (CGFloat)width;
    - (void)setWidth:(CGFloat)width;
    
    - (CGFloat)height;
    - (void)setHeight:(CGFloat)height;
    
    - (CGFloat)bottom;
    - (void)setBottom:(CGFloat)bottom;
    
    - (CGFloat)right;
    - (void)setRight:(CGFloat)right;
    
    1. .m内容
    - (CGPoint)origin{
        return self.frame.origin;
    }
    - (void)setOrigin:(CGPoint)origin{
        CGRect frame = self.frame;
        frame.origin = origin;
        self.frame = frame;
    }
    
    - (CGSize)size{
        return self.frame.size;
    }
    - (void)setSize:(CGSize)size{
        CGRect frame = self.frame;
        frame.size = size;
        self.frame = frame;
    }
    
    - (CGFloat)x{
        return self.frame.origin.x;
    }
    - (void)setX:(CGFloat)x{
        CGRect frame = self.frame;
        frame.origin.x = x;
        self.frame = frame;
    }
    
    - (CGFloat)y{
        return self.frame.origin.y;
    }
    - (void)setY:(CGFloat)y{
        CGRect frame = self.frame;
        frame.origin.y = y;
        self.frame = frame;
    }
    
    - (CGFloat)width{
        return self.frame.size.width;
    }
    - (void)setWidth:(CGFloat)width{
        CGRect frame = self.frame;
        frame.size.width = width;
        self.frame = frame;
    }
    
    - (CGFloat)height{
        return self.frame.size.height;
    }
    - (void)setHeight:(CGFloat)height{
        CGRect frame = self.frame;
        frame.size.height = height;
        self.frame = frame;
    }
    
    - (CGFloat)bottom{
        return self.frame.origin.y + self.frame.size.height;
    }
    - (void)setBottom:(CGFloat)bottom{
        CGRect frame = self.frame;
        frame.origin.y = bottom - self.frame.size.height;
        self.frame = frame;
    }
    
    - (CGFloat)right{
        return self.frame.origin.x + self.frame.size.width;
    }
    - (void)setRight:(CGFloat)right{
        CGRect frame = self.frame;
        frame.origin.x = right - self.frame.size.width;
        self.frame = frame;
    }
    

    附:我的博客地址

    相关文章

      网友评论

        本文标题:iOS UIView分类

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