UITableViewCell更改selectedBackgroundView alpha?

我需要更改UITableViewCell的selectedBackgroundView的alpha。 所以我做了以下几点:

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; } 

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

尝试这个:

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

编辑::
在提供子视图的alpha值时存在一个已知问题。 看看这个线程更好地理解: iOS控制子视图的UIView阿尔法行为

 // 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单元格select颜色?