好的,所以這裏的關鍵是我沒有使用IB,因爲我正在使用的視圖是以編程方式創建的。 UIView
覆蓋屏幕的下半部分,並在其上有一堆按鈕。但是,我想向UIView
添加更多按鈕,而不會使其更大。爲此,我想在視圖內製作一個UIScrollView
,這將允許我在屏幕外添加更多按鈕,以便用戶可以滾動到它們。我認爲這就是它的工作原理。如何以編程方式創建UIScrollView?
self.manaView = [[[UIView alloc] initWithFrame:frame] autorelease];
self.manaView.backgroundColor = [UIColor purpleColor];
UIScrollView *scroll = [UIScrollView alloc];
scroll.contentSize = CGSizeMake(320, 400);
scroll.showsHorizontalScrollIndicator = YES;
[self.manaView addSubview:scroll];
代碼的第一部分iniates我UIView
,偉大的工程,但我無法弄清楚如何使UIScrollView
編程,並將其添加到視圖,然後將按鈕添加到它。
UIButton *ret2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
ret2.tag = 102;
ret2.frame = CGRectMake(255, 5, 60, 50);
[ret2 setTitle:@"Return" forState:UIControlStateNormal];
[ret2 addTarget:self action:@selector(flipAction:) forControlEvents:UIControlEventTouchUpInside];
[scroll addSubview:ret2];
當我這樣做時,按鈕只是從我的屏幕上消失。那麼我如何正確地做到這一點?感謝您的幫助!
啊,我必須有initwithframe AND .contentSize才能使用它。謝謝! – 2010-06-08 15:42:22