How do I control the position of an image in a grouped table cell?

For some reason, I am unable to change the default position of the image in the grouped tableview cell.

The cellForRowAtIndexPath method uses the following to load the image:

cell.imageView.image = [UIImage imageWithContentsOfFile:MainImagePath];

      

I experimented with the following to adjust the position of the image, but no luck.

cell.contentMode = UIViewContentModeCenter;

      

I've tried this too with no luck.

cell.imageView.contentMode = UIViewContentModeCenter;

      

+2


source to share


3 answers


Can you use the imageFrameView ie: cell.imageView.frame = CGFrameMake (0.0, 0.0, 20.0, 20.0);

or set the center of the image with

cell.imageView.center = CGPointMake (20.0, 10.0);



= Set

EDITED: Thanks Jonah, I fixed this!

+2


source


The default layout for UITableViewCell is [imageView] [textLabel] [xsesen. screen]. You cannot change this.



If you want to arbitrarily place an image in your UITableViewCell, you must add the UIImageView to the cell contentView

.

+2


source


To move imageView

you need to change it. What you are doing is just reconfiguring how it reacts to image resizing. Try installing cell.imageView.center

to the new hub you want.

You should know tableView:willDisplayCell:forRowAtIndexPath:

. This is called just before the cell is displayed and is your last (and often best) chance to set the layout. tableView:cellForRowAtIndexPath:

is called much earlier and its results are cached. Thus, the layout may be faulty by the time it is actually displayed (due to image resizing, for example). This is why we usually do the layout in tableView:willDisplayCell:forRowAtIndexPath:

.

+1


source







All Articles