发现一个写UIButton的位置方法挺不错的,保存一下

/ 0评 / 0
You have to set UIButton frame your self.

Horizontally Alignment

float X_Co = (self.view.frame.size.width - yourButtonWidth)/2;
[button setFrame:CGRectMake(X_Co, yourYposition, yourButtonWidth, yourButtonheight)];
Vertically Align

float Y_Co = (self.view.frame.size.height - yourButtonheight)/2;
[button setFrame:CGRectMake(yourXposition, Y_Co, yourButtonWidth, yourButtonheight)];
TOP LEFT

[button setFrame:CGRectMake(0.0, 0.0, yourButtonWidth, yourButtonheight)]; 
TOP RIGHT

float X_Co = self.view.frame.size.width - yourButtonWidth;
[button setFrame:CGRectMake(X_Co, 0.0, yourButtonWidth, yourButtonheight)];
BOTTOM LEFT

float Y_Co = self.view.frame.size.height - yourButtonheight;
[button setFrame:CGRectMake(0.0, Y_Co, yourButtonWidth, yourButtonheight)];
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)];
Center Of self.view

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)];

来自地址:http://stackoverflow.com/questions/12387988/how-to-programmatically-allign-a-button-in-ios-applications

发表评论

邮箱地址不会被公开。 必填项已用*标注