Can a standard accessory view be in a different position within a UITableViewCell? Can a standard accessory view be in a different position within a UITableViewCell? ios ios

Can a standard accessory view be in a different position within a UITableViewCell?


No, you cannot move where the accessory view is. As an alternative you can add a subview like the following;

[cell.contentView addSubview:aView];

Also, by setting the accessoryView property equal to something, the accessoryType value is ignored.


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

Use at your own risk (this code snippet moves any accessoryView 8 pixels to the left. Call [self positionAccessoryView]; from inside the -(void)layoutSubviews method of the desired UITableViewCell subclass):

- (void)layoutSubviews {    [super layoutSubviews];    [self positionAccessoryView];}- (void)positionAccessoryView {    UIView *accessory = nil;    if (self.accessoryView) {        accessory = self.accessoryView;    } else if (self.accessoryType != UITableViewCellAccessoryNone) {        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 &&                [subview isKindOfClass:[UIButton class]]) {                accessory = subview;                break;            }        }    }    CGRect r = accessory.frame;    r.origin.x -= 8;    accessory.frame = r;}


I was able to change the accessory view's frame by simply doing this in my custom cell subclass.

CGRect adjustedFrame = self.accessoryView.frame;adjustedFrame.origin.x += 10.0f;self.accessoryView.frame = adjustedFrame;


matomo