UITableViewCell更改selectedBackgroundView alpha?

问题描述 投票:2回答:2

我需要改变alphaselectedBackgroundViewUITableViewCell。所以我做了以下事情:

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没有影响。

ios objective-c uitableview
2个回答
2
投票

试试这个:

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

编辑:: 在为子视图提供alpha值时存在一个已知问题。看看这个帖子以便更好地理解:iOS controlling UIView alpha behaviour for subviews


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

希望这个链接对你有用。

Changing background color of selected cell?

UITableView Cell selected Color?

© www.soinside.com 2019 - 2024. All rights reserved.