I am targeting iOS 7 and 8, and I want to eliminate the margin appearing on the left side of the images in this UITableView below. I would even be willing to accept a solution that only works on iOS 8 if the solution is simple/elegant. (I would just live with the margin on iOS 7 as it dies out).
This is what I would like it to look like:
I have read through many similar questions on Stack Overflow (such as this one), or ones specific to grouped UITableViews (here and here), but cannot seem to get any to work quite right.
For example, if I try to solve the problem using contentInset (a common answer on SO):
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tableView.contentInset = UIEdgeInsetsMake(self.tableView.contentInset.top, -16, self.tableView.contentInset.bottom, self.tableView.contentInset.right);
self.tableView.separatorInset = UIEdgeInsetsMake(0, 33, 0, 0);
}
Then I end up with the gap on the right side of the tableview:
I get why it's happening, the entire tableview is just shifted over, as seen in the Debug View Hierarchy screen:
However, I've tried adjusting the tableView frame size to compensate, but it never seems to work correctly. Plus this seems hacky; there must be a better way.
For the record, here's my cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get a cell that we can use]
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VideoCell" forIndexPath:indexPath];
cell.textLabel.numberOfLines = 0;
cell.selectedBackgroundView = selectionColor;
cell.accessoryView = [[UIImageView alloc] initWithImage:[PTStyleKit imageOfArrow]];
// Create the attributed string (text + attributes)
NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:[videos objectAtIndex:indexPath.row] attributes:attributes];
// Set it in our UILabel and we are done!
[cell.textLabel setAttributedText:attributedText];
NSString* filename = [filenames objectAtIndex:indexPath.row];
if (filename == nil)
{
filename = cell.textLabel.text;
}
UIImage *imageOne = [UIImage imageNamed:[NSString stringWithFormat:@"medium-%@", filename]];
cell.imageView.image = [UIImage imageWithCGImage:imageOne.CGImage scale:imageOne.size.height/44 orientation:imageOne.imageOrientation];
return cell;
}