问题描述
我使用来自笔尖的自定义 UITableViewCell.附件视图是一个详细信息披露指示器.问题是辅助视图后面的 UITableViewCell 的背景颜色没有被渲染(参见下面的图像/源代码).有什么线索吗?另外,这里有一些我尝试过但没有奏效的方法:
I use a custom UITableViewCell from a nib. The accessory view is a Detail Disclosure Indicator . The problem is that the background color of the UITableViewCell behind the accessory view is not getting rendered (see image / source below). Any clues? Also, here are some things that I tried but did NOT work:
没有用的东西:
- 将附件视图的 backgroundColor 设置为 clearColor
- 将单元格的 contentView.opaque 设置为 FALSE
- 将表格视图的 contentView.opaque 设置为 FALSE
- 为单元格设置非默认附件视图
Things that DID NOT work:
- Setting the backgroundColor of the accessory view to clearColor
- Setting the contentView.opaque of the cell to FALSE
- Setting the contentView.opaque of the Table View to FALSE
- Setting a non-default accessory view for the cell
替代文字 http://www.chicknchoke.com/so/IMG_8028.png
-(void)showTablePrep
{
myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 480, 320, 416) style:UITableViewStylePlain];
myTableView.dataSource = self;
myTableView.delegate = self;
myTableView.delaysContentTouches = FALSE;
myTableView.opaque = FALSE;
myTableView.rowHeight = 60;
[UIView beginAnimations:@"SlideUp" context:nil];
[UIView setAnimationDuration:0.3f];
[myTableView setCenter:CGPointMake(myTableView.center.x, myTableView.center.y-436)];
[self.view addSubview:myTableView];
[self.view bringSubviewToFront:myTableView];
[UIView commitAnimations];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FriendsCell* cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellID"];
if (cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FriendsCellView" owner:self options:nil];
cell = (FriendsCell*)[nib objectAtIndex:0];
if(indexPath.row % 2 == 0){
cell.contentView.backgroundColor = [UIColor grayColor];
}else{
cell.contentView.backgroundColor = [UIColor lightGrayColor];
}
cell.accessoryView.backgroundColor = [UIColor clearColor];
cell.contentView.opaque = FALSE;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if(f
riendsCounter > indexPath.row){
cell.titleLabel.text = @"Label";
cell.descLabel.text = @"Description goes here";
}else{
cell.titleLabel.text = @"";
cell.descLabel.text = @"";
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
return cell;
}
推荐答案
您为单元格绘制的背景颜色不正确.UITableViewCell
将被安排以便 contentView
和 accessoryView
并排放置.(这样做是为了 contentView
可以剪辑其内容,使其不与附件视图重叠)问题不在于附件视图不透明,而是根本没有绘制灰色背景在附件视图后面.
You're drawing the background color for your cell incorrectly. A UITableViewCell
will be arranged so that the contentView
and accessoryView
sit side-by-side. (This is done so that the contentView
can clip its content so it doesn't overlap with the accessory view) The problem is not that the accessory view is opaque, it's that the gray background is simply not drawn behind the accessory view.
自定义UITableViewCell
背后绘制的背景的正确方法是自定义backgroundView
.我没有尝试过,但由于您只是更改颜色,您可以简单地将 backgroundView
上的 backgroundColor
颜色设置为您想要的颜色.
The correct way of customizing the background drawn behind a UITableViewCell
is to customize its backgroundView
. I haven't tried this, but since you're only changing the color, you might be able to simply set the backgroundColor
color on the backgroundView
to your desired color.
这篇关于如何在 UITableViewCell 中获得透明的附件视图?(带截图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!