Ios UITableViewCell更改已选择BackgroundView alpha?

Ios UITableViewCell更改已选择BackgroundView alpha?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我需要为UITableViewCell的selectedBackgroundView更改alpha。因此,我做了以下工作: UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reu

我需要为
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;
}
已选择红色单元格,但alpha设置对bgView无效。

请尝试以下操作:

[bgView setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.5]];
编辑::
在子视图上提供alpha值时存在一个已知问题。查看此线程以更好地理解:

希望这个链接对你有用

// 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];