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


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

声明:Sandy'Blog|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 发现一个写UIButton的位置方法挺不错的,保存一下


一流的吃貨,二流的廚藝,三流的技術,下流的人品