如何在UITableView中更改附件视图的alpha?

时间:2014-02-25 06:08:57

标签: ios objective-c uitableview

我正在UITableView中为配件视图设置图像。我正在尝试减少此视图的alpha。这是我尝试过的,但不起作用。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

      UIImageView *accessoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu.png"]];
      accessoryImageView.alpha = 0.7;
      cell.accessoryView = accessoryImageView;
      return cell;

}

也试过这个,没有成功:

 - (UITableViewCell *)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

      UIImageView *accessoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu.png"]];
      accessoryImageView.alpha = 0.7;
      cell.accessoryView = accessoryImageView;
      return cell;

 }

4 个答案:

答案 0 :(得分:2)

UITableViewCell的SubClass,试试这个:

- (void)layoutSubviews{
    [super layoutSubviews];
    self.accessoryView.alpha = 0.7f;
}

答案 1 :(得分:0)

试试这段代码..

   [accessoryImageView setBackgroundColor:[[UIColor orangeColor] colorWithAlphaComponent:0.5]];

答案 2 :(得分:0)

试试这个

 - (UITableViewCell *)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

          UIImageView *accessoryImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"menu.png"]];
          [accessoryImageView setBackgroundColor:[[UIColor darkGrayColor] colorWithAlphaComponent:0.7]];;
          cell.accessoryView = accessoryImageView;
          return cell;

     }

答案 3 :(得分:0)

在willDisplayCell方法

中添加此内容
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.accesoryView.alpha = 0.4;
}