我想添加一個在另一個下方的按鈕。我有這個簡單的代碼:將按鈕添加到另一個下方
- (void)viewDidLoad
{
[super viewDidLoad];
for(int i=0 ; i<9 ; i++)
{
UIButton *myButton = [[UIButton alloc] init];
myButton.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height/10); //this "10" i want also dynamically
myButton.backgroundColor = [UIColor blackColor];
[self.view addSubview:myButton];
}
}
當然,我知道它會畫一個在另一個。但我可以在不知道高度的循環中做到這一點(因爲高將取決於循環中將有多少個按鈕)。
我想達到的目標:
但是,如果你添加100個按鈕,他們會有點小,不是嗎?爲什麼不將按鈕添加到uiscrollview? – divol 2012-07-23 08:04:56
如果我想出如何添加一個在另一個下面,這不會是一個問題添加滾動視圖。 – Kuba 2012-07-23 08:09:02