I want to add horizontal padding for my table view cells as the image shows.
I created a subclass of UITableViewCell
, whose width was 314 pixels (screen's width is 320), and set its frame in the initWithCoder
method:
[self customizeXPosition:self.profileImage];
[self customizeXPosition:self.birthdayLabel];
[self customizeXPosition:self.heightLabel];
[self customizeXPosition:self.weightLabel];
this is my - (void)customizeXPosition:(UIView *)view
:
- (void)customizeXPosition:(UIView *)view {
CGRect tmpRect = view.frame;
tmpRect.origin.x += 3.0;
view.frame = tmpRect;
}
The custom cell was smaller than screen, and I moved every element in the cell to right by 3 pixels. I thought this code should achieve my goal, yet it didn't. The view didn't change in the simulator, just like I didn't write any code.
how can I achieve my goal?
Try overriding the -setFrame method in UITableViewCell as per this post :
How to set the width of a cell in a UITableView in grouped style
Swift version
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