UITableViewCell imageView causes too much indention

I have a subclassed UITableViewCell that I am setting the imageView for. I want to keep it at 60x60, so I set the frame and bounds in the layoutSubviews method of my subclass:

- (void)layoutSubviews {
    [super layoutSubviews];

    self.imageView.bounds = CGRectMake(10,10,60,60);
    self.imageView.frame = CGRectMake(10,10,60,60);
    self.imageView.clipsToBounds = YES;

}//end

This works great, until I have an image that goes outside of the bounds of the imageView:

Because of that, I make sure to set clipsToBounds to YES:

But as you can see it is still indenting the textLabel and detailTextLabel even though I don't think it should be.

How can I fix this issue?

Answers


You can set the position of your textLabel in your -layoutSubviews implementation:

- (void)layoutSubviews {
    [super layoutSubviews];

    self.imageView.bounds = CGRectMake(10,10,60,60);
    self.imageView.frame = CGRectMake(10,10,60,60);
    self.imageView.clipsToBounds = YES;

    CGFloat x = 10.0 + 60.0 + 10.0; // Padding, image width, and padding.

    CGRect frame = self.textLabel.frame;
    frame.origin.x = x;
    self.textLabel.frame = frame;

    frame = self.detailTextLabel.frame;
    frame.origin.x = x;
    self.detailTextLabel.frame = frame;

} //end

You probably want to adjust the value of x.

Hope this helps.


I think the better solution, which I went with, was to not use the build in imageView but to roll my own. This worked much better.


Need Your Help

How to remove white space between div elements

html css

I created a web page with 3 div tags with some content in each div and with background colors set to the div elements I found some white space appearing between the div elements.

Javadoc through Ant task with {@inheritDoc} from J2SE classes

java ant javadoc inheritdoc

I generate documentation for a project using an Ant task. In several places, I wanted to inherit documentation from the standard classes, so I used {@inheritDoc} which allowed me to see the Javadoc...