I want my accessory to be in a slightly different place than normal. Is it possible? This code has no effect:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.accessoryView.frame = CGRectMake(5.0, 5.0, 5.0, 5.0);
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With