The*_*ger 54
你必须设置UIButton自己的框架.
水平对齐
float X_Co = (self.view.frame.size.width - yourButtonWidth)/2;
[button setFrame:CGRectMake(X_Co, yourYposition, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
垂直对齐
float Y_Co = (self.view.frame.size.height - yourButtonheight)/2;
[button setFrame:CGRectMake(yourXposition, Y_Co, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
左上方
[button setFrame:CGRectMake(0.0, 0.0, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
右上
float X_Co = self.view.frame.size.width - yourButtonWidth;
[button setFrame:CGRectMake(X_Co, 0.0, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
左下方
float Y_Co = self.view.frame.size.height - yourButtonheight;
[button setFrame:CGRectMake(0.0, Y_Co, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
BOTTOM RIGHT
float X_Co = self.view.frame.size.width - yourButtonWidth;
float Y_Co = self.view.frame.size.height - yourButtonheight;
[button setFrame:CGRectMake(X_Co, Y_Co, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
自我中心
button.center = self.view.center;
OR
float X_Co = (self.view.frame.size.width - yourButtonWidth)/2;
float Y_Co = (self.view.frame.size.height - yourButtonheight)/2;
[button setFrame:CGRectMake(X_Co, Y_Co, yourButtonWidth, yourButtonheight)];
Run Code Online (Sandbox Code Playgroud)
Vim*_*lan 20
您可以设置按钮的中心以相应地放置它
yourButton.center = CGPointMake(0.0, 0.0);// for topleft
yourButton.center = CGPointMake(160.0, 240.0);// for center
yourButton.center = CGPointMake(320.0, 480.0);// for bottomright
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
设置子视图位置的唯一方法是手动.您可以像这样设置框架,例如:

或者更改原点,例如:
view.frame.origin.x = INT_VALUE;
获得某种对齐的唯一方法是使用数学self.view.frame.如果要将对象水平对齐到屏幕中间,请使用:
view.frame.origin.x = self.view.frame.size.width / 2
如果您想以44像素的边距将顶部对齐到顶部,请使用:
view.frame.origin.y = self.view.frame.origin.y = (view.frame.size.height / 2) + 44;
等等.