By default the accessoryView
on the UITableViewCell
is positioned to the far right on the cell. I am sub-classing the UITableViewCell
to try and change this position to move it over more the left, however, it has no effect and it remains to the right. Any ideas on how to do this?
- (void) layoutSubviews
{
[super layoutSubviews];
self.accessoryView.frame = CGRectMake(100, self.accessoryView.frame.origin.y, self.accessoryView.frame.size.width, self.accessoryView.frame.size.height);
self.accessoryView.layer.borderWidth = 1;
self.accessoryView.layer.borderColor = [[UIColor redColor] CGColor];
}
Implement layoutSubviews
in your cell subclass, call super as the first thing you do and then modify the frames of the subviews you want to change.
This is similar to Flea's solution; pushes the image by the given amount instead of a fixed frame:
static CGFloat const kRightOffset = 10.0;
cell.accessoryView = ({UIImageView * imgV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image.png"]];
CGRect frame = imgV.frame;
frame.size.width = frame.size.width + kRightOffset;
imgV.frame = frame;
[imgV setContentMode:UIViewContentModeLeft];
imgV; });
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