【问题标题】:UITableViewCell change selectedBackgroundView alpha?UITableViewCell 更改 selectedBackgroundView 阿尔法?
【发布时间】:2013-09-20 08:30:29
【问题描述】:

我需要将 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 无效。

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:
    // 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?

    【讨论】:

      【解决方案2】:

      试试这个:

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

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

      【讨论】:

        猜你喜欢
        • 2023-03-05
        • 2013-02-26
        • 2016-06-21
        • 1970-01-01
        • 2011-08-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-22
        相关资源
        最近更新 更多