查找按钮的位置。 CGRectMake [英] Finding the position of a button. CGRectMake
问题描述
我有一个按钮,我使用 CGRectMake
将其放置如下:
I have a button and I'm using CGRectMake
to position it like this:
btn5.frame = CGRectMake(211, 280, 109, 60);
我想 211
和 280
是按钮的坐标。
I guess 211
and 280
are the coordinates of the button. So how can I modify that code if I want the button to be near the bottom left corner.
推荐答案
是的,你是正确的。按钮的框架定义它在其父视图上的位置。因此,如果使用此代码, btn5
将位于位置(x = 211,y = 280),并且将具有尺寸(width = 109,hight = / p>
Yes, you are correct. The frame of the button defines where it is located on its parent view. So btn5
will be in the position (x = 211, y = 280) and will have the dimensions (width = 109, hight = 60) if you use this code:
btn5.frame = CGRectMake(211, 280, 109, 60);
一般表达式为:
btn5.frame = CGRectMake(buttonX, buttonY, buttonWidth, buttonHeight);
如果要更改按钮的位置到左下角,你可以这样做:
If you want to change the position of the button to the bottom left corner, you can do like this:
btn5.frame = CGRectMake(0, self.view.frame.size.height - 60, 109, 60);
如果要在按钮和角落之间添加一些空格,按钮:
If you want to add some space between the button and the corner, and also change the size of the button:
CGFloat x = leftPadding;
CGFloat y = self.frame.size.width - desiredHeight - bottomPadding;
btn5.frame = CGRectMake(x, y, desiredWidth, desiredHeight);
有关详细信息,请检查Apple的查看几何和坐标系指南。
这篇关于查找按钮的位置。 CGRectMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!