所以現在我想移動按鈕的位置,如果它是一個iPhone 5的屏幕或沒有,但我無法弄清楚如何移動按鈕,現在我有一個「if語句」,可以圖如果它是iPhone 5或不是,但我不知道如何在聲明中移動我的按鈕。看看我的代碼。以編程方式移動UIButton?
.H
-(IBAction)randomButton;
//the button i want to move
.M提前
- (void)viewDidLoad
{
[super viewDidLoad];
if (IS_IPHONE_5) {
//I don't know how to move the button in here.
}
}
感謝。
如果您以編程方式移動按鈕只是爲了適應不同的屏幕尺寸或高寬比,那麼您正在爲自己工作。這正是spring-and-struts(pre-iOS 6)和自動佈局(iOS 6及以上)機制的作用。如果你從頭開始學習自動佈局,而不是使用spring-and-struts;這是蘋果希望你去的方式。嘗試看看這個介紹:http://www.raywenderlich.com/20881/beginning-auto-layout-part-1-of-2 – davidf2281