Reputation: 13329
I want the textview to be before the scrollview inside my tablecell like this, so that the scrollview scrolls and the titles stays put.
[Title goes here] - it does not move with the scrollview
---------------------
| |
| ScrollView |
| |
---------------------
This is my code, the textView appears behind the scrollview.
-(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;
}
Upvotes: 0
Views: 92
Reputation: 5312
Why cant you just set the frame of your titleView to, say, (0,0,width,titleHeight)
and then set the frame of your scrollView to (0,titleHeight,width,cellHeight-titleHeight)
.
This will just place the title at the top part of the cell, setting it's height to whatever you make titleHeight
to be, and will put the scrollView at the bottom part of the cell, setting it's height to the rest of the cell.
Upvotes: 1