I would like to set up margins or paddings for UITableView cells imageView, how could I do that?
With heightForRowAtIndexPath
I can only set rows height. And it
This works on iOS 7:
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect imageViewFrame = self.imageView.frame;
imageViewFrame.origin.x = 10;
imageViewFrame.origin.y += 5;
imageViewFrame.size.height -= 10;
imageViewFrame.size.width -= 10;
self.imageView.frame = imageViewFrame;
}
Without subclassing:
cell.imageView.transform = CGAffineTransformScale(CGAffineTransformIdentity, .5, .5);
change the '.5' with the right proportion for your case
updated for swift3
cell?.imageView?.transform = CGAffineTransform(scaleX: 0.6, y: 0.6)
The best solution here is to create your own cell, add image, labels inside of contentView
and tweak them how you want.
But there's also another way, again you need to create a subclass from UITableViewCell
and override layoutSubviews
selector:
- (void)layoutSubviews
{
[super layoutSubviews];
self.imageView.frame = CGRectMake(10, 10, 50, 50);
self.imageView.contentMode = UIViewContentModeCenter;
}