试试这个
- (UITableViewCell *) tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier: @"any-cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: @"any-cell"];
UIView* bgView = [[UIView alloc] initWithFrame: cell.bounds];
bgView.backgroundColor = [UIColor whiteColor];
UIView* halfView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, cell.bounds.size.width/2.0, cell.bounds.size.height)];
halfView.backgroundColor = [UIColor greenColor];
[bgView addSubview: halfView];
cell.backgroundView = bgView;
}
return cell;
}
需要明确的是,我的问题是“如何改变该行的只剩一半的背景颜色? – DDR
准确地说,将一个常规视图添加到行的左半部分,然后添加您想要的任何内容,并确保它位于“文档大纲”面板中视图的上方。 – dbmrq
哦,实际上情况恰恰相反,它必须低于文档大纲中的背景视图。我会用一个例子更新我的答案 – dbmrq