简体   繁体   中英

How to add a Round rect button outside of a cell in a UITableView?

How do I add a round rect button outside of a cell in a UITableView?

For example :

在此处输入图片说明

The "Other","home" & "home" fields are all independent cells.

What I am trying to achieve is the ability to add buttons such as the "Text Message","Share Contact" & "Add to favorites" shown above.

Thanks in advance for the advice!

Simply add a footer (or header) to the appropriate section.

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *yourView = [[UIView alloc] initWithFrame:CGRectMake(x,x,x,x)];

    UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    yourButton.frame = CGRectMake(x,x,x,x);
    [yourButton setTitle:@"Title" forState:UIControlStateNormal];

    [yourView addSubview:yourButton];

    return yourView;
}

Basically there are two options within regular UITableViews.

  1. It is a cell with transparent background of the content view and of the cell itself.
  2. It is a section header. Noting stops you from inventing a new section exactly there, a section with 0 rows even. And you overwrite the tableView:viewForHeaderInSection: method and provide an appropriate header with buttond and whatever you like. This one, too, shold have a transparent background.

You need a custom cell with a transparent background and you can add those buttons on it. Alternatively, you could use the section footer to do pretty much the same.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM