0

How do I align the table cell button to the left instead of the right? Below is the code I am using to create the UIButton. Thanks.

cell.accessoryView = [self getButton: @"icon.png"];

...

- (UIButton*)getButton: (NSString*)icon {
    UIImage *image = (true) ? [UIImage   imageNamed:icon] : [UIImage imageNamed:icon];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
    button.frame = frame;
    [button setBackgroundImage:image forState:UIControlStateNormal];

    [button addTarget:self action:@selector(checkButtonTapped:event:)  forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];
    return button;

}
joe
  • 16,988
  • 36
  • 94
  • 131
  • 1
    From my past experience, the best way to accomplish this is to roll your own table view cell or add the button as a subview and not using the accessoryView. – ry_donahue Mar 29 '12 at 20:16

2 Answers2

1

You are adding the button as an accessory view, which cannot be put on the left. See this question, it is almost exactly the same:

iOS UITableViewCell accessory on the left side?

Community
  • 1
  • 1
rosslebeau
  • 1,283
  • 6
  • 6
0

Then you can muck with the frame of the button.

UIButton *cellButton = [self getButton:@"icon.png"];
[cell.contentView addSubview:cellButton];
Sam
  • 2,579
  • 17
  • 27