Look at the topic and know what this article is written about.
BackBtn.frame.size = cgmakesize (+); This is the wrong way to do it.
In OC, a member of the struct property of an object is not allowed to be modified, the above statement, BACKBTN is an object that we instantiate, frame is its struct property, and size is the member variable of the property of the frame. According to OC syntax, we know that the above code is wrong. If you want to set size, we do this:
CGRect frame = backbtn.frame;
Frame.size = cgmakesize (+);
<pre name= "code" class= "OBJC" >backbtn.frame = frame;
The solution above is to assign the structure property of the original object to a temporary structure, then modify the members in the temporary structure, and then assign the modified struct variable directly to the structure variable of the original object, which is equivalent to the modification.
But we know that there are many such members, such as Origin in frame, x in Size,origin, width in y,size, height. Each member of us is very troublesome to assign, so I suggest you add a category (category) so that each object's attributes can be directly assigned, and the tedious statements of the assignment are written in category.
#import <UIKit/UIKit.h>
@interface UIView (Extension)
@property (nonatomic, assign) CGFloat x;
@property (nonatomic, assign) CGFloat y;
@property (nonatomic, assign) cgfloat width;
@property (nonatomic, assign) cgfloat height;
@property (nonatomic, assign) cgsize size;
@property (nonatomic, assign) Cgpoint origin;
@end
#import "Uiview+extension.h" @implementation UIView (Extension)//Override set Method-(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;
}-(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) SetSize: (cgsize) Size {CGRect frame = self.frame;
frame.size = size;
Self.frame = frame;
}-(void) Setorigin: (Cgpoint) origin {CGRect frame = self.frame;
Frame.origin = origin;
Self.frame = frame;
}//Override Get Method-(CGFloat) x {return self.frame.origin.x;}
-(CGFloat) y {return self.frame.origin.y;}
-(CGFloat) width {return self.frame.size.width;}
-(cgfloat) height {return self.frame.size.height;} - (cgsize) Size {return self.frame.size;}
-(Cgpoint) origin {return self.frame.origin;} @end
Add: Only write header file is also possible, I think it should be @property automatically generated the corresponding get and set method. This is debatable.