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.