2

我需要更改alpha. 所以我做了以下事情:selectedBackgroundViewUITableViewCell

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleBlue;

    UIView *bgView = [UIView new];
    bgView.backgroundColor = [UIColor redColor];
    bgView.alpha = 0.5;//This setting has no effect
    cell.selectedBackgroundView = bgView;
}

单元格以红色选择,但 alpha 设置对 bgView 没有影响。

4

2 回答 2

3
// set selection color

UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
myBackView.backgroundColor = [UIColor colorWithRed:1 green:0.0 blue:0.0 alpha:0.5];
cell.selectedBackgroundView = myBackView;
[myBackView release];

希望这个链接对你有用。

更改所选单元格的背景颜色?

UITableView 单元格选择颜色?

于 2013-09-16T09:07:57.547 回答
3

尝试这个:

[bgView setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.5]];

编辑::
为子视图提供 alpha 值存在一个已知问题。查看此线程以获得更好的理解:iOS control UIView alpha behavior for subviews

于 2013-09-16T08:49:41.760 回答