zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    flutter资料
    flutter兼论
    Dart 学习
    flutter简易教程
    全球15个顶级技术类博客
    Grunt压缩HTML和CSS
    用grunt搭建自动化的web前端开发环境-完整教程
    正确代码之-grunt
    grunt写一个px和rem互转的工具
    unslider使用方法1
  • 原文地址:https://www.cnblogs.com/peaker-wu/p/5689963.html
Copyright © 2011-2022 走看看