0

我有一个表格视图,我正在动态重新加载其内容,为了重新加载表格内容,我使用以下代码:

[agendaTable reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

这工作正常,但问题是我以下列方式设置表格单元格的 alpha 属性:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {


    if([cell isKindOfClass:[AgendaItemBlank class]])
        cell.backgroundColor = [UIColor clearColor];

    else if([cell isKindOfClass:[AgendaItem class]])
    {
        cell.backgroundColor = [UIColor whiteColor];

        [cell setAlpha:0.82];

        //set the corner radius so that there is a rounded effect
        [cell.layer setBorderWidth:0.5];
        [cell.layer setCornerRadius:9.0];
        [cell.layer setBorderColor:[UIColor redColor].CGColor];
        [cell.layer setMasksToBounds:YES];

        //set a different color for the selected background
        UIView *bgColorView = [[UIView alloc] init];
        [bgColorView setBackgroundColor:[UIColor redColor]];
        [bgColorView.layer setCornerRadius:9.0];
        [cell setSelectedBackgroundView:bgColorView];
        [bgColorView release];
    }
}

这些因素的结合导致重新加载后,表格单元格最初变得不透明,所有属性都生效,但 alpha 属性不生效。

单元格在向上和向下滚动时(主要是在重绘时)恢复其 alpha 属性。

我也尝试在 内设置 alpha - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,但这没有任何效果。

4

2 回答 2

0

尝试

[cell setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.82]];
[cell.textLabel setBackgroundColor:[UIColor clearColor]];
于 2012-05-07T18:07:04.840 回答
0

要设置单元格背景,请使用中间UIView对象:

UIView* cellBackView = [[UIView alloc] initWithFrame:CGRectZero];
cellBackView.backgroundColor = [UIColor redColor];
cellBackView.alpha = 0.82;
cell.backgroundView = cellBackView;
于 2012-05-07T18:00:49.793 回答