1. Okay, then, next, we will show you how to implement Autoresizing through code,
Ok, so, next, why do we say this through code to achieve Autoresizing,
Then, note that we can operate through our storyboard, so don't implement it through code,
The future trend is that Apple recommends that we all use storyboards,
Click to implement, no code is needed,
You are not allowed to write code,
But why tell this now,
Because, when you are working, is it very possible that you encounter, or the previous project,
When encountering previous projects, other people wrote codes, and he implemented them with codes.
At that time, there was no storyboard,
It does this through code,
Do you have to know how to change?
will change, so the purpose is to, or, we can, take over other people's projects,
So, let me tell you,
How to implement Autoresizing through code,
Okay, pay attention, let me remind everyone, when you write this case after class, you must use pure code to create each control,
Don't pass, drag on the storyboard, don't pass the dragged control,
The dragged-up control will have some default settings, which will affect the effect of your operation.
So, when you write code next, you must create those sub-controls in a pure code way like me,
OK, so next, the case,
Case 3, what is the demand
Listen carefully, case 3 is such a requirement,
1) First, I'm going to
Dynamically create two Views,
One is blue View
One is the red View
The width and height of the blue View are 200,
The distance from the blue View to X is 0
The distance from Y is also 0,
The red View has a width of 200, is it the same as the blue View?
The red View is inside the blue View, and the red View is a child control of the blue View.
The width of the red View is also 200,
The height of the red View is 50,
At the same time, the red View is close to the bottom edge of the blue View,
to show,
Is it like the effect we saw,
2) Then, next, put a button on the View of our controller,
When the button is clicked, let the height and width of the blue View be accumulated, so that the height and width of the blue View become larger,
The height and width of the blue View outside have become larger,
3) Then, require the implementation:
The red View, no matter how the height and width of the blue View change, the red View is always close to the bottom edge of the blue View,
And, to fill this width, to display,
And, the height of the red View is constant,
That is to say, this is the effect at the beginning. When you click the button, the blue View becomes larger, and the red View always sticks to the bottom edge to display, and increases as the width of the blue View increases.
The height of the red View is unchanged, right?
Then, next, let's implement this together,
this is very simple
Take this, I will build another one for it, this one is unnecessary,
Name: 002 Autoresizing through code
Ok, let's change the screen size first,
Changed to 3.5 inches,
Okay, next, now, do we want to dynamically create two Views through code?
2. Create two Views through code
1. OK, so turn on our controller,
In the view of this controller, in the loaded event,
What we have to do is to create a blue View,
//Create a blue View
//Create a red View
UIView *blueVw = [[UIView alloc] init];
Blue View, do you have to set the background color?
//Set the background color
blueVw.backgroundColor = [UIColor blueColor ] ;
set its frame
//set frame
Is it possible for us to see it,
Note, what I said, using Autoresizing, Autolayout, do not set the frame, refers to: If you set this through Autoresizing, Autolayout, uh, for example, is the distance to the right and the distance of it equivalent to setting It's X, and Y, right,
After setting this X, and Y, there is no need to set the frame again.
But if, for example, you don't set height and width here,
Still need to set by frame,
That’s not to say, if Autoresizing, Autolayout, and frame are absolutely used, they must never be set.
is not what it means,
It means that if you have set the height, width, or X and Y in this frame through Autoresizing and Autolayout,