• iOS 添加view的分类(更加方便的设置view的位置)


    点击创建UIView的分类category,这里命名为 PLExtension(为了和下面对应)

    view分类.h文件

    #import <UIKit/UIKit.h>
    
    @interface UIView (PLExtension)
    @property (nonatomic, assign) CGFloat WL_width;
    @property (nonatomic, assign) CGFloat WL_height;
    @property (nonatomic, assign) CGFloat WL_x;
    @property (nonatomic, assign) CGFloat WL_y;
    @property (nonatomic, assign) CGFloat WL_centerX;
    @property (nonatomic, assign) CGFloat WL_centerY;
    
    @property (nonatomic, assign) CGFloat WL_right;
    @property (nonatomic, assign) CGFloat WL_bottom;
    @end

    .m文件

    #import "UIView+PLExtension.h"
    
    @implementation UIView (WLExtension)
    
    - (CGFloat)WL_width
    {
        return self.frame.size.width;
    }
    
    - (CGFloat)WL_height
    {
        return self.frame.size.height;
    }
    
    - (void)setWL_(CGFloat)WL_width
    {
        CGRect frame = self.frame;
        frame.size.width = WL_width;
        self.frame = frame;
    }
    
    - (void)setWL_height:(CGFloat)WL_height
    {
        CGRect frame = self.frame;
        frame.size.height = WL_height;
        self.frame = frame;
    }
    
    - (CGFloat)WL_x
    {
        return self.frame.origin.x;
    }
    
    - (void)setWL_x:(CGFloat)WL_x
    {
        CGRect frame = self.frame;
        frame.origin.x = WL_x;
        self.frame = frame;
    }
    
    - (CGFloat)WL_y
    {
        return self.frame.origin.y;
    }
    
    - (void)setWL_y:(CGFloat)WL_y
    {
        CGRect frame = self.frame;
        frame.origin.y = WL_y;
        self.frame = frame;
    }
    
    - (CGFloat)WL_centerX
    {
        return self.center.x;
    }
    
    - (void)setWL_centerX:(CGFloat)WL_centerX
    {
        CGPoint center = self.center;
        center.x = WL_centerX;
        self.center = center;
    }
    
    - (CGFloat)WL_centerY
    {
        return self.center.y;
    }
    
    - (void)setWL_centerY:(CGFloat)WL_centerY
    {
        CGPoint center = self.center;
        center.y = WL_centerY;
        self.center = center;
    }
    
    - (CGFloat)WL_right
    {
        //    return self.WL_x + self.WL_width;
        return CGRectGetMaxX(self.frame);
    }
    
    - (CGFloat)WL_bottom
    {
        //    return self.WL_y + self.WL_height;
        return CGRectGetMaxY(self.frame);
    }
    
    - (void)setWL_right:(CGFloat)WL_right
    {
        self.WL_x = WL_right - self.WL_width;
    }
    
    - (void)setWL_bottom:(CGFloat)WL_bottom
    {
        self.WL_y = WL_bottom - self.WL_height;
    }
    
    @end
    

      

  • 相关阅读:
    haproxy报错解决
    haproxy安装
    gitlab配置webhook报错解决
    git_push报错
    DNS配置
    centos7 选定默认启动内核,及删除无用内核
    ansible安装、配置ssh、hosts、测试连接
    公司手机打卡app时间和百度时间差30秒解决
    所有编辑语言的共性内容元素
    php使用正则函数使用详解
  • 原文地址:https://www.cnblogs.com/peaker-wu/p/5689963.html
Copyright © 2020-2023  润新知