IOS Add View categories (more convenient to set the view location)

Source: Internet
Author: User
Tags uikit

Click Create UIView category, which is named Plextension (to correspond to the following)

View category. h file

#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 file

#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_width: (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

  

IOS Add View categories (more convenient to set the view location)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.