所以我要定製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