2010-10-17 23 views
2

我想要使用非常大的分段控件組件,所以我的想法是通過水平滾動來使其在uiscrollview ..so中可以選擇適當的項目。 我寫了這個代碼:在uiscrollview中創建一個uisegmentedcontrol

CGRect rect = [[UIScreen mainScreen] applicationFrame]; 
CGRect frame = CGRectMake(rect.origin.x + kLeftMargin, rect.size.height - kPaletteHeight - kTopMargin, 2*rect.size.width , kPaletteHeight); 
seg.frame = frame; 

scroll.frame = frame; 
scroll.contentSize = CGSizeMake(frame.size.width * 2,frame.size.height); 
scroll.showsHorizontalScrollIndicator = YES; 
scroll.showsVerticalScrollIndicator = NO; 
scroll.scrollsToTop = NO; 
[scroll addSubview:seg]; 

但滾動視圖沒有讓segmentedcontrol待觀察。 我的錯誤在哪裏?

+0

有同樣的問題!你最終的決定是什麼? – 2011-03-11 10:14:55

+0

我有我的問題,我可以看到我的分段控制,我可以水平滾動,但我無法選擇創建時未顯示的段。任何人? – zambono 2011-11-07 19:34:55

回答

6

也許這將幫助你:

UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 435)]; 
scroll.contentSize = CGSizeMake(320, 700); 
scroll.showsHorizontalScrollIndicator = YES; 

NSArray *itemArray = [NSArray arrayWithObjects: @"One", @"Two", @"Three", nil]; 
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; 
segmentedControl.frame = CGRectMake(35, 200, 250, 50); 
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; 
segmentedControl.selectedSegmentIndex = 1; 

[scroll addSubview:segmentedControl]; 
[segmentedControl release]; 
[self.view addSubview:scroll]; 
0

您可以使用UICollectionView,水平滾動使用的按鈕小區。

+0

的確,從2010年開始,問題日期有所改變..其中一個是現在我們有UICollectionView :) – 2017-05-08 11:32:24

相關問題