Search code examples
iphonecocoa-touchuikit

Decrease UITableViewCell width and put custom button on the left


Is there any way to decrease the standard width of grouped UITableViewCell and put a custom button on the left side(outside of cell boundary)? I tried to change the cell size but it keeps same

alt text


Solution

  • You are going to have to fake the editing mode. What I mean by that is that as AtomRiot said you have to subclass UITableViewCell so that when in editing mode you show the button you want on the left, outside the cell.

    But first things first. To change the indentation level for your cells all you need to do is implement this delegate method for the UITableView

    - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
    

    So that takes care of it. Then in your UITableViewCell subclass all I would do is to implement the method

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    

    which I assume is called when the table the cell belongs to has changed to editing mode. There I would fade in (or animate in any way you want) a button to appear on the left of your cell. I have done it inside a grouped-style cell but never on the outside. Give it a try!