我需要改变alpha
为selectedBackgroundView
的UITableViewCell
。所以我做了以下事情:
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值时存在一个已知问题。看看这个帖子以便更好地理解:iOS controlling UIView alpha behaviour for subviews
// 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];
希望这个链接对你有用。