zoukankan      html  css  js  c++  java
  • iOS-UIView一些坐标和位置方法封装

    新建基于UIView扩展类 UIView+wkjFrame,此类是为了方便获取一些基于UIView类UI控件的坐标和位置的简化,直接引用即可

    UIView+wkjFrame.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)height;
    - (void)setHeight:(CGFloat)height;
    
    - (CGFloat)width;
    - (void)setWidth:(CGFloat)width;
    
    - (CGFloat)tail;
    - (void)setTail:(CGFloat)tail;
    
    - (CGFloat)bottom;
    - (void)setBottom:(CGFloat)bottom;
    
    - (CGFloat)right;
    - (void)setRight:(CGFloat)right;

    UIView+wkjFrame.m

    #import "UIView+wkjFrame.h"
    
    @implementation UIView (wkjFrame)
    - (CGPoint) origin {
        return self.frame.origin;
    }
    
    - (void) setOrigin:(CGPoint) point {
        self.frame = CGRectMake(point.x, point.y, self.frame.size.width, self.frame.size.height);
    }
    
    - (CGSize) size {
        return self.frame.size;
    }
    
    - (void) setSize:(CGSize) size {
        self.frame = CGRectMake(self.x, self.y, size.width, size.height);
    }
    
    - (CGFloat) x {
        return self.frame.origin.x;
    }
    
    - (void) setX:(CGFloat)x {
        self.frame = CGRectMake(x, self.y, self.width, self.height);
    }
    
    - (CGFloat) y {
        return self.frame.origin.y;
    }
    - (void) setY:(CGFloat)y {
        self.frame = CGRectMake(self.x, y, self.width, self.height);
    }
    
    - (CGFloat) height {
        return self.frame.size.height;
    }
    - (void)setHeight:(CGFloat)height {
        self.frame = CGRectMake(self.x, self.y, self.width, height);
    }
    
    - (CGFloat)width {
        return self.frame.size.width;
    }
    - (void)setWidth:(CGFloat)width {
        self.frame = CGRectMake(self.x, self.y, width, self.height);
    }
    
    - (CGFloat)tail {
        return self.y + self.height;
    }
    
    - (void)setTail:(CGFloat)tail {
        self.frame = CGRectMake(self.x, tail - self.height, self.width, self.height);
    }
    
    - (CGFloat)bottom {
        return self.tail;
    }
    
    - (void)setBottom:(CGFloat)bottom {
        [self setTail:bottom];
    }
    
    - (CGFloat)right {
        return self.x + self.width;
    }
    
    - (void)setRight:(CGFloat)right {
        self.frame = CGRectMake(right - self.width, self.y, self.width, self.height);
    }
    @end
  • 相关阅读:
    python3删除mysql上月分区数据(脚本)
    ansible之基本原理及命令
    centOS 7 简单设置(虚拟机)
    TCP_Wrappers 简介
    sudo
    引用数据应该选择 ID, CODE 还是 NAME
    吃得洒脱是一种什么体验
    通用数据同步机制
    我的学PyTorch之路(1)
    38岁才学会了游泳的心得
  • 原文地址:https://www.cnblogs.com/wangkejia/p/8474134.html
Copyright © 2011-2022 走看看