0
我希望textview位於我的表格內部的滾動視圖之前,以便滾動視圖滾動並且標題保持放置狀態。在uiScrollView之前添加uiTextView
[Title goes here] - it does not move with the scrollview
---------------------
| |
| ScrollView |
| |
---------------------
這是我的代碼,TextView的出現滾動視圖後面。
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"];
}
NSInteger numberOfViews = 10;
UIScrollView *vwScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1280, 200)];
for (int i = 0; i < numberOfViews; i++) {
CGFloat xOrigin = i * 250;
UITextView *titleView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 1280, 20)];
titleView.text = @"Title";
[titleView setFont:[UIFont fontWithName:@"HelveticaBold" size:32]];
UIView *awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, 250, 180)];
awesomeView.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5/i/10 blue:0.5 alpha:1];
[awesomeView.layer setBorderColor:[UIColor whiteColor].CGColor];
[awesomeView.layer setBorderWidth:10.5f];
awesomeView.layer.shadowPath = [UIBezierPath bezierPathWithRect:awesomeView.bounds].CGPath;
[cell.contentView addSubview:titleView];
[vwScroll addSubview:awesomeView];
}
vwScroll.contentSize = CGSizeMake(250 * numberOfViews, 200);
[cell.contentView addSubview:vwScroll];
return cell;
}
看起來TextView在scrollview的後面.. – Harry 2013-03-19 07:49:09
您是否將scrollView的Y座標設置爲與textView的高度相同? – Jsdodgers 2013-03-19 07:55:00
啊這就是問題!男人,我沒有想到這一點,謝謝,添加到您的答案,並給我一個綠色標記:-) – Harry 2013-03-19 07:56:43