Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set the alpha property of a UITableViewCell accessoryView?

Tags:

iphone

I'm using a UIImageView as the accessoryView in a UITableViewCell that I'm creating programmatically. I've tried everything I can think of to set the accessoryView's alpha property, but it's not working. I'm able to set the hidden and opaque properties with no problems, but alpha is hating all over me.

I tried creating a new project that contains a single UITableViewController and the following tableView:cellForRowAtIndexPath: method:

- (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;
}

As you may have guessed, the accessoryView is fully opaque. Am I missing something? I can't find any information about what's going on here.

Thanks!

like image 508
No Surprises Avatar asked Sep 17 '09 00:09

No Surprises


People also ask

What is accessoryview iOS?

The view to use on the right side of the cell, typically as a control, in the table view's normal state. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.0+ tvOS 9.0+


1 Answers

After trying about a billion different things and looking everywhere for some answers, I ended up just faking it by adding a subview to the cell's contentView and positioning it to the accessory position. I'm able to set the alpha property on that subview to my heart's content.

like image 122
No Surprises Avatar answered Sep 28 '22 03:09

No Surprises