0
我幾乎看到有關類似問題的所有問題,並嘗試給出答案,但它們不適合我。問題是:我有一個主視圖,並且我有一個按鈕,點擊後,它會在它上面添加一個新按鈕和一個標籤,等等,直到您「填充」該區域,並且我希望它可以調整大小和滾動,所以你可以看到所有的按鈕,你可以放大隻看到一些按鈕。我不知道我是否清楚地解釋自己...如何將UIButtons和UILabels添加到可滾動視圖?
所以,我試圖添加一切到一個UIView,它沒有工作,我試圖添加一切到一個UIScrollView,並且它沒有工作。我不知道還有什麼要做。我幾乎整個一週都在處理這個問題,但沒有取得任何成功。我不得不說我對此並不是很有經驗,我剛剛在4個月前開始爲iOS編碼,所以請耐心等待。我真的很感激任何幫助或指導,你可以分享。
下面是我在做什麼:
- (IBAction) doneAdding:(id) sender{
boxes = boxes+1;
UIButton *newBox = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *boxImage = [UIImage imageNamed:@"bluecube.jpg"];
if (boxes <= 4) {
switch (boxes) {
case 1:
newBox.frame = CGRectMake(519, 356, 162, 163);
break;
case 2:
newBox.frame = CGRectMake(681, 519, 162, 163);
break;
case 3:
newBox.frame = CGRectMake(357, 519, 162, 163);
break;
case 4:
newBox.frame = CGRectMake(519, 844, 162, 163);
break;
default:
break;
}
[newBox setBackgroundImage:boxImage forState:UIControlStateNormal];
[newBox addTarget:self action:@selector(goToProject:) forControlEvents:UIControlEventTouchUpInside];
[homeView addSubview:newBox];
//I get the text of the label from a textfield
UILabel *nameLabel= [ [UILabel alloc ] initWithFrame:CGRectMake(480.0,500.0, 150.0, 43.0) ];
[[NSUserDefaults standardUserDefaults] setObject: newName.text forKey: @"SomeRandomText"];
nameLabel.textAlignment = UITextAlignmentCenter;
nameLabel.textColor = [UIColor blackColor];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.font = [UIFont fontWithName:@"Helvetica" size:(12.0)];
nameLabel.text = [NSString stringWithFormat:@"%@", newName.text];
[homeView addSubview:nameLabel];
[newName release];
}else {
NSLog(@"No more boxes allowed");
}
}
是的,我做了,但它不會滾動。我檢查了所有必須在IB上檢查的複選框,但沒有運氣。 –
我沒有在那裏看到任何'[homeView setContentSize:]'。 – MrMage
我沒有設置它的程序,我說IB內部...有什麼區別嗎? –