• UIView的分类--iOS


    #import <UIKit/UIKit.h>

    @interface UIView (PJXExtension)

    @property(assign,nonatomic) CGFloat x; //x坐标

    @property(assign,nonatomic) CGFloat y; //y坐标

    @property(assign,nonatomic) CGFloat width; //宽度

    @property(assign,nonatomic) CGFloat height; //高度

    @property(assign,nonatomic) CGFloat centerX; //中心点X值

    @property(assign,nonatomic) CGFloat centerY; //中心点Y值

    @end

     

    #import "UIView+PJXExtension.h"

    @implementation UIView (PJXExtension)

    //x

    -(void)setX:(CGFloat)x{

        CGRect frame = self.frame;

        frame.origin.x = x;

        self.frame = frame;

    }

    -(CGFloat)x{

        return self.frame.origin.x;

    }

    //y

    -(void)setY:(CGFloat)y{

        CGRect frame = self.frame;

        frame.origin.y = y;

        self.frame = frame;

    }

    -(CGFloat)y{

        return self.frame.origin.y;

    }

    //width

    -(void)setWidth:(CGFloat)width{

        CGRect frame = self.frame;

        frame.size.width = width;

        self.frame = frame;

    }

    -(CGFloat)width{

        return self.frame.size.width;

    }

    //height

    -(void)setHeight:(CGFloat)height{

        CGRect frame = self.frame;

        frame.size.height = height;

        self.frame = frame;

    }

    -(CGFloat)height{

        return self.frame.size.height;

    }

    //centerX

    -(void)setCenterX:(CGFloat)centerX{

        CGRect frame = self.frame;

        frame.origin.x = centerX - frame.size.width/2.0;

        self.frame = frame;

    }

    -(CGFloat)centerX{

        return CGRectGetMidX(self.frame);

    }

    //centerY

    -(void)setCenterY:(CGFloat)centerY{

        CGRect frame = self.frame;

        frame.origin.y = centerY - frame.size.height/2.0;

        self.frame = frame;

    }

    -(CGFloat)centerY{

        return CGRectGetMidY(self.frame);

    }

    /*

     //中心X

     -(CGFloat)centerX

     {

     return  self.center.x;

     }

     -(void)setCenterX:(CGFloat)centerX

     {

     CGPoint center = self.center;

     center.x = centerX;

     self.center = center;

     }

     //中心点Y

     -(CGFloat)centerY

     {

     return  self.center.y;

     }

     -(void)setCenterY:(CGFloat)centerY

     {

     CGPoint center = self.center;

     center.y = centerY;

     self.center = center;

     }

     */

    @end

  • 相关阅读:
    时尚意
    ​runtime 运行时机制
    ios-UIAlertView,UIActionSheet-常用方法
    ios-UIActivityIndicatorView-常用方法
    ios-UIPageControl-常用方法
    ios-UISegmentedControl-常用方法
    ios-UISlider-常用方法和定时器NSTimer的使用
    ios-UITextField-常用方法
    java捕获特定异常特定处理
    ios-UIButton-常用方法
  • 原文地址:https://www.cnblogs.com/PJXWang/p/5854811.html
Copyright © 2020-2023  润新知