如何在頂部創建水平滾動視圖,如具有多個按鈕的滾動菜單(例如:20個按鈕)? 請幫忙!具有n個按鈕的水平滾動視圖:[iOS]
我使用下面的代碼:
CGRect buttonFrame = CGRectMake(0.0f, 0.0f, scrollView.frame.size.width, scrollView.frame.size.height);
for (NSString *text in wordsArray) {
UIButton *button = [[UIButton alloc]initWithFrame:buttonFrame];
button.text = text;
[scrollView addSubview:button];
buttonFrame.origin.x +=buttonFrame.size.width;
}
CGSize contentSize = scrollView.frame.size;
contentSize.width = buttonFrame.origin.x;
scrollView.contentSize = contentSize;
,但沒有得到我想要的東西。
請檢查這個答案,我認爲這是一個,你在找什麼http://stackoverflow.com/questions/6688160/how-to-programmatically-add-a -uisegmentedcontrol-to-a-container-view/6689592#6689592 – Wolverine