在uiScrollView之前添加uiTextView
问题描述:
我希望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;
}
答
为什么不能你刚才设置你的titleview的,比方说,(0,0,width,titleHeight)
的框架,然后设置你的滚动视图的框架(0,titleHeight,width,cellHeight-titleHeight)
。
这只会将标题放在单元格的顶部,将其设置为高度,无论您将titleHeight
设置为什么,并将scrollView放置在单元格的底部,并将其设置为高度细胞。
看起来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