是否可以设置UITableViewCell accessoryView的alpha属性?

No *_*ses 12 iphone

我使用的是UIImageView作为accessoryView一个UITableViewCell我要创建的程序.我用尽了一切我能想到的来设置accessoryViewalpha属性,但它不工作.我能够毫无问题地设置hiddenopaque属性,但是却alpha在讨厌我.

我尝试创建一个包含单个UITableViewController和以下tableView:cellForRowAtIndexPath:方法的新项目:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = @"Cell";

    UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
    cell.accessoryView = iv;
    [iv release];

    // cell.accessoryView.hidden = YES; // works
    cell.accessoryView.alpha = 0.5f;    // fails

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

你可能已经猜到了,它accessoryView是完全不透明的.我错过了什么吗?我找不到任何关于这里发生了什么的信息.

谢谢!

小智 5

也许你可以在willDisplayCell中做到这一点:

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.accesoryView.alpha = 0.4;
}
Run Code Online (Sandbox Code Playgroud)


No *_*ses 3

在尝试了大约十亿种不同的事情并到处寻找一些答案之后,我最终只是通过向单元格的 contentView 添加子视图并将其定位到附件位置来伪造它。我可以根据自己的喜好设置该子视图的 alpha 属性。