just ME
just ME

Reputation: 1827

iOS how to add radio buttons

I would like to add in my ViewController something that should look identical with the first item of this picture (Simple passcode + radio button). Do I need to use a UITableView and define the hearder and the footer for this? Can someone provide me some examples of how to start and work with this?

I would like to add in my ViewController something that should look identical with the first item of this picture (Simple passcode + radio button). Do I need to use a UITableView and define the hearder and the footer for this? Can someone provide me some examples of how to start and work with this?

Upvotes: 0

Views: 790

Answers (2)

David Berry
David Berry

Reputation: 41226

Simplest solution is to set up a UITableViewController using static layout in interface builder.

enter image description here

Then set up your table however you want it to look:

enter image description here

Upvotes: 0

Infinity James
Infinity James

Reputation: 4735

You need a custom UITableViewCell with a UILabel on the left side of the cell, and a UISwitch on the right side.

Register the custom cell class with the table view and a cell identifier and then customise it as you would any other cell.

static NSString *const CellIdentifier = @"customCell";

/**
 *  Called after the controller’s view is loaded into memory.
 */
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.tableView registerClass:[CustomCell class] forCellIdentifier:CellIdentifier];
}

/**
 *  Asks the data source for a cell to insert in a particular location of the table view.
 *
 *  @param  tableView                   A table-view object requesting the cell.
 *  @param  indexPath                   An index path locating a row in tableView.
 *
 *  @return An object inheriting from UITableViewCell that the table view can use for the specified row.
 */
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.textLabel.text = @"Simple Passcode";

    return cell;
}

Upvotes: 1

Related Questions