I think the topic may not be very clear, then I would like to introduce in detail this essay content.
The size of the UIView control cannot be changed externally.
This is said to be uiview, but in fact, most controls are not just uiview.
What to do if you want to implement a size that cannot be changed externally.
The first is to rewrite the setframe so that it prescribes itself as size, as follows
testview.m// cx-Implementation cannot be changed externally UIView size//// Created by Ma C on 16/3/25.// Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "TestView.h" @implementation testview-(void) Setframe: (cgrect) frame{frame.size = Cgsizemake (+); [Super Setframe:frame];} @end
After rewriting the setframe we can test it.
I'm in VC. The size of the TestView is set to {200,200}.
This shows that the size of the Uitestview cannot be changed externally
But the following results are not.
We first set up the Uitestview center.
Then set the Uitestview bounds
viewcontroller.m// cx-Implementation cannot be changed externally UIView size//// Created by Ma C on 16/3/25.// Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "ViewController.h" #import "TestView.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload { [super viewdidload]; TestView * view = [[TestView alloc]init]; View.center = Self.view.center; View.bounds = CGRectMake (0, 0, $, +); [Self.view Addsubview:view]; NSLog (@ "%@", Nsstringfromcgrect (View.frame)); } @end
The results are as follows
Visible: Uitestview size has changed, it's okay.
Let's rewrite the bounds.
testview.m// cx-Implementation cannot be changed externally UIView size//// Created by Ma C on 16/3/25.// Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "TestView.h" @implementation testview-(void) Setframe: (cgrect) frame{frame.size = Cgsizemake (+); [Super Setframe:frame];} -(void) SetBounds: (cgrect) bounds{ bounds.size = cgsizemake (+); [Super Setbounds:bounds];} @end
The results are as follows:
testview.m// cx-Implementation cannot be changed externally UIView size//// Created by Ma C on 16/3/25.// Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "TestView.h" @implementation testview-(void) Setframe: (cgrect) frame{frame.size = Cgsizemake (+); [Super Setframe:frame];} -(void) SetBounds: (cgrect) bounds{ bounds.size = cgsizemake (+); [Super Setbounds:bounds];} @end
This concludes that if you want the UIView control to be unable to change size externally, we only need to rewrite the frame,bounds.
In the same vein, we can also implement some other operations.
IOS Miscellaneous Pen-11 (implements a size that cannot be changed externally UIView)