iOS: How to move UITableViewCellAccessory Button to the left

I'm trying to develop a UITableView which has sectionIndexTitles and which cells have accessory buttons.

The problem is that the scrollbar for the index titles decreases the width of the cells and so the accessory buttons are at an ugly position...

Is it possible to move the button slightly to the left that they are inside the cell?

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text = @"text";
    }

    return cell;
}

As you can see I don't manipulate the cell or something like that.

And here you can see the result:

http://i.stack.imgur.com/3AB89.jpg

Answers


There is a way to move default accessoryView, but its pretty hacky. So it might stop working one day when new sdk arrives.

Use at your own risk (this code snippet moves any accessoryView 8 pixels to the left, insert it inside -(void)layoutSubviews method of desired uitableviewcell subclass):

if (self.accessoryView) {
    r = self.accessoryView.frame;
    r.origin.x -= 8;
    self.accessoryView.frame = r;
} else {
    UIView* defaultAccessoryView = nil;
    for (UIView* subview in self.subviews) {
        if (subview != self.textLabel && 
            subview != self.detailTextLabel && 
            subview != self.backgroundView && 
            subview != self.contentView &&
            subview != self.selectedBackgroundView &&
            subview != self.imageView) {
            defaultAccessoryView = subview;
            break;
        }
    }
    r = defaultAccessoryView.frame;
    r.origin.x -= 8;
    defaultAccessoryView.frame = r;
}

Need Your Help

What is a good pattern for inexact queries in the Google App Engine Datastore?

google-app-engine gql google-cloud-datastore

The Google App Engine Datastore querying language (gql) does not offer inexact operators like "LIKE" or even case insensitivity. One can get around the case sensitive issue by storing a lower-case

How to locate an SAPUI5 control in a control container and display it in topside part?

javascript html sapui5

In the right side I want to locate the desired row and display it in topside part, Below is my code: