1
所以我有一堆UIViews
我編程製作並放置了一堆的內容上(UIButtons
,UILabels
,UINavigationBars
等),大多數的這些意見都將需要實際上是代替UIScrollViews
。轉換UIViews做編程到UIScrollViews
現在請記住,我通過代碼而不是Interface Builder來完成所有這些。我第一次嘗試的是將UIView
的每個聲明更改爲UIScrollView
,而編譯並運行良好,但是,它們不可滾動。這真的很奇怪。
這裏是我變成UIScrollViews
的代碼,雖然它不滾動:
- (void)loadView {
//allocate the view
self.view = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
//set the view's background color
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"MainBG.jpg"]];
[self.view addSubview:[SiteOneController myNavBar1:@"Sites"]];
NSMutableArray *sites = [[NSMutableArray alloc] init];
NSString *one = @"Constution Center";
NSString *two = @"Franklin Court";
NSString *three = @"Presidents House";
[sites addObject: one];
[one release];
[sites addObject: two];
[two release];
[sites addObject: three];
[three release];
NSString *element;
int j = 0;
for (element in sites)
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIFont *myBoldFont = [UIFont boldSystemFontOfSize:20.0];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, b + (j*45), c, d)];
[label setBackgroundColor:[UIColor clearColor]];
label.text = element;
label.font = myBoldFont;
UIImage *img = [UIImage imageNamed:@"ButtonBase.png"];
[button setImage:img forState:UIControlStateNormal];
//setframe (where on screen)
//separation is 15px past the width (45-30)
button.frame = CGRectMake(a, b + (j*45), c, d);
// [button setTitle:element forState:UIControlStateNormal];
button.backgroundColor = [SiteOneController myColor1];
[button addTarget:self action:@selector(showCCView:)
forControlEvents:UIControlEventTouchUpInside];
[button setTag:j];
[self.view addSubview: button];
[self.view addSubview:label];
j++;
}
}
我在做什麼錯?
太棒了。非常感謝。我會記下這一點。 – Scott 2010-03-19 00:38:01
但還有一個問題。我可能在我原來的問題上犯了一個錯誤。這將整個UIView轉換爲UIScrollView。這意味着現在,當我滾動甚至導航欄滾動它...你如何使UIScrollView只佔用標籤欄上方的空間,但在導航欄下方。 – Scott 2010-03-19 01:43:09
假設'SiteOneController'是一個UINavigationBarController,您可能需要更改代碼,以便在SiteOneController中添加UIScrollView,以解決您的問題。 – 2010-03-19 02:01:08