所以我要定制UITableViewCell
选定背景视图。在这里我做了什么:自定义高度的UITableViewCell选择背景视图
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
CGRect cellFrame = [tableView rectForRowAtIndexPath:indexPath];
CGRect selectedBackgroundFrame = cellFrame;
UIView *selectedBackgroundView = [[UIView alloc] init];
selectedBackgroundFrame.size.height = 5;
[selectedBackgroundView setFrame:selectedBackgroundFrame];
selectedBackgroundView.backgroundColor = [UIColor colorWithRed:180/255.0
green:138/255.0
blue:171/255.0
alpha:1];
NSLog(@"%f %f %f %f",
selectedBackgroundFrame.size.width,
selectedBackgroundFrame.size.height,
selectedBackgroundFrame.origin.x,
selectedBackgroundFrame.origin.y);
cell.selectedBackgroundView = selectedBackgroundView;
return cell;
}
但结果是选择背景视图仍填充整个细胞,而不是我的预期是高度5.
它还打印正确的事情320.000000 5.000000 0.000000 0.000000
。怎么了?
您的意思是,您想在选择它之后增加单元高度吗? –
不,是selectedBackgroundView。编辑我的帖子.. – Rendy
你可以尝试打印'selectedBackgroundView.frame'。并且selectedBackgroundView的颜色显示是否正常? – anhtu