Search for button position. CGRectMake

I have a button, and I use CGRectMaketo position it like this:

btn5.frame = CGRectMake(211, 280, 109, 60);

I think 211and 280are the coordinates of the button. Since I can change this code if I want the button to be in the lower left corner.

-2
source share
2 answers

Yes you are right. The button frame determines where it is in the parent view. Thus, it btn5will be in position (x = 211, y = 280) and will have dimensions (width = 109, hight = 60) if you use this code:

btn5.frame = CGRectMake(211, 280, 109, 60);

General expression:

btn5.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);

If you want to change the position of the button in the lower left corner, you can do the following:

btn5.frame = CGRectMake(0, self.view.frame.size.height - 60, 109, 60);

, :

CGFloat x = leftPadding;
CGFloat y = self.frame.size.width - desiredHeight - bottomPadding;
btn5.frame = CGRectMake(x, y, desiredWidth, desiredHeight); 

. Apple " " .

+1

CGRectMake (211, 280, 109, 60) .

- x y ( )

- .

, , x 0 ( 0 ) y - 60 ( 60 - ). , x y.

+1

All Articles