ios - 如何设置 Tableview 单元格的 alpha 值

标签 ios uitableview

我有一个 UITableView。我在那个 Tableview 中有 4 个单元格。

我的 Tableview alpha 值为 0.8。

但我的要求是我希望前 3 个单元格的 alpha 值是 0.8,第 4 个单元格的 alpha 值是 1.0。

那么如何根据单元格设置这些alpha值呢?

请帮帮我。我最近 2 天遇到了这个问题。

这是我的代码:

   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      UITableViewCell *cell = nil;
      NSString *simpleTableIdentifier = [NSString stringWithFormat:@"%@%d",@"Cell",indexPath.row];
      if (indexPath.row == 0)
      {
         cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
         if (cell == nil)
         {
             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
             cell.alpha = 0.8;
         }
      }
      else if (indexPath.row == 1)
      {
            cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
            if (cell == nil)
            {
               cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
               cell.alpha = 0.8;
            }
      }
      else if(indexPath.row == 2)
      {
              cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
              if (cell == nil)
              {
                 cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
                 cell.alpha = 0.8;
              }
       }
       else if (indexPath.row == 3)
       {
              cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
               if (cell == nil)
              {
                   cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
                   cell.alpha = 1.0;
              }
       }
        return cell;
     }

最佳答案

我希望这一行代码能解决您的问题

cell.contentView.alpha = 0.8

关于ios - 如何设置 Tableview 单元格的 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26093563/

相关文章:

swift - 如何让单元格在我的 ViewController2 中打印?

ios - 分析 iPad 项目的内存泄漏

ios - 准备在 UITabbarController 中不调用 segue

ios - 单击 UITableViewCell 时打开新的 UIViewController?

ios - UITableView 单元格在高度变化后显示错误的内容

ios - 滚动 UITableView 时仪器显示 "_NSContiguousstring"内存泄漏

ios - 警报后打开一个新的 View Controller

javascript - iOS 13+ 设备的网络音频音量衰减

ios - 如何在单行 Collection View 中显示选定的照片

ios - 如何为uitableview自定义多选编辑模式