0

I've tried a bunch of stuff - adding a button from the object browser, changing attributes, searching the web, but no luck. Essentially, I'd like to do --in the storyboard--: pin screenshoot

where you see "add to contacts" "share location" and "add to bookmarks".

ari gold
  • 2,074
  • 3
  • 25
  • 51
  • I realize that I'd like to be able to do this in the storyboard as it's a graphical thing. I found [this](http://stackoverflow.com/questions/9605381/how-to-add-a-footer-to-a-uitableview-in-storyboard) but the background is white - I'd like the table background (grey vertical stripes) to come through. – ari gold Aug 09 '12 at 21:11

3 Answers3

4

You should create a UITableViewCell whose contentView holds 3 separate UIButtons. To do this programmatically, in your tableView:cellForRowAtIndexPath: data source method, you can use code similar to the following:

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* identifier = @"cell";
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.backgroundColor = [UIColor clearColor];
        UIButton* button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        UIButton* button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        UIButton* button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button1.frame = UIEdgeInsetsInsetRect(cell.contentView.bounds, UIEdgeInsetsMake(0, 0, 0, 250)); 
        button2.frame = UIEdgeInsetsInsetRect(cell.contentView.bounds, UIEdgeInsetsMake(0, 125, 0, 125)); 
        button3.frame = UIEdgeInsetsInsetRect(cell.contentView.bounds, UIEdgeInsetsMake(0, 250, 0, 0)); 
        button1.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
        button2.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;
        button3.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
        [cell.contentView addSubview:button1];
        [cell.contentView addSubview:button2];
        [cell.contentView addSubview:button3];
    }

    return cell;
}

Also, in the tableView:willDisplayCell: method of your delegate, do the following to have the default decoration of the cell totally disappear:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundView = nil;
}

You should obtain a result very similar to what you posted.

amadour
  • 1,600
  • 11
  • 20
2

Put the three buttons in a UIView that is 320 pixels wide and say 60 hight, and make that view the footer of your table.

David H
  • 40,852
  • 12
  • 92
  • 138
2

The UITableView is styled using the UITableViewStyleGrouped stye.
The three UIButtons are programmatically added to the tableView.tableFooterView.
Alternatively, you can add three UIButtons to the contentView of the last cell.

Add buttons like:

UIButton *theButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
theButton.frame = CGRectMake(20, 20, 200, 40); 
[theButton setTitle:@"Button" forState:UIControlStateNormal];
[theButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:theButton];

Get the button positions correctly using trial and error :)

Anne
  • 26,765
  • 9
  • 65
  • 71