IOS miscellaneous pen-12 (class de clever use of Frame operations), ios-12

Source: Internet
Author: User

IOS miscellaneous pen-12 (class de clever use of Frame operations), ios-12

In actual development, many times we are overwhelmed by frame control operations.

For example, we only want to get the width of the view.

We can do this: view. frame. size. width

Sometimes we want to change the width of the view, but we cannot change it directly-> we need a trilogy.

We can change the category to achieve the desired effect.

The following is a. h file of the category:

/// UIView + CXExtension. h //// Created by ma c on 16/3/25. // Copyright©2016 xubaoaichiyu. all rights reserved. // # import <UIKit/UIKit. h> @ interface UIView (CXExtension) @ property (nonatomic, assign) CGSize size; @ property (nonatomic, assign) CGFloat width; @ property (nonatomic, assign) CGFloat height; @ property (nonatomic, assign) CGFloat x; @ property (nonatomic, assign) CGFloat y; @ end

Next is the. m file

/// UIView + CXExtension. m // Created by ma c on 16/3/25. // Copyright©2016 xubaoaichiyu. all rights reserved. // # import "UIView + CXExtension. h "@ implementation UIView (CXExtension)-(void) setSize :( CGSize) size {CGRect frame = self. frame; frame. size = size; self. frame = frame;}-(CGSize) size {return self. frame. size;}-(void) setWidth :( CGFloat) width {CGRect frame = self. frame; frame. size. width = width; self. frame = frame;}-(void) setHeight :( CGFloat) height {CGRect frame = self. frame; frame. size. height = height; self. frame = frame;}-(void) setX :( CGFloat) x {CGRect frame = self. frame; frame. origin. x = x; self. frame = frame;}-(void) setY :( CGFloat) y {CGRect frame = self. frame; frame. origin. y = y; self. frame = frame;}-(CGFloat) width {return self. frame. size. width;}-(CGFloat) height {return self. frame. size. height;}-(CGFloat) x {return self. frame. origin. x;}-(CGFloat) y {return self. frame. origin. y ;}@ end

Copy and paste the file to use it, or change it to another price control.

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.