3

I need some help, I'm using SDWebImage to display my images in my Xcode app but I'm also trying to show text using the tableView's testLabel. But what is happening is the image is pushing the textLabel to the right, next to the image instead of being on top of the image. I'm not using a UIImageView or a label, I'm using the tableviews default imbedded imageView and textLabel. Any idea on how I can display this textLabel on top of sdwebimage's loaded image? I want to display the text at the bottom left of the cell, on top of the loaded image.

I can't post an image so I will try my best at describing what my problem looks like.

Image Description: In the cell, there is an image with a 7px margin on each side, to the right of the image there is the textLabel showing only 2-3 characters before the rest disappearing out of the screen.

My Code:

Loading the image:

NSURL * imgURL = [[gamesArray objectAtIndex:indexPath.row] valueForKey:@"gameURL"];
[cell.imageView setContentMode:UIViewContentModeScaleAspectFit];
[cell.imageView sd_setImageWithURL:imgURL placeholderImage:[UIImage imageNamed:@"placeholder.png"] options:SDWebImageRefreshCached];

Loading the text:

cell.textLabel.text = gameObject.gameName;
[cell.textLabel setContentMode:UIViewContentModeScaleToFill];
cell.textLabel.textColor = [UIColor whiteColor];
Julien Quere
  • 2,407
  • 16
  • 21
WokerHead
  • 947
  • 2
  • 15
  • 46

2 Answers2

2

In default TableView cell image is always in centre and textLabel is right to imageView. So for this you have to design a custom TableView cell.

Yogesh Mv
  • 1,041
  • 1
  • 6
  • 12
  • It makes sense now. How would I do this? Any links. I have the prototype cell but I just change the height on it. – WokerHead Oct 12 '16 at 18:03
1

Instead of setting the default cell image view, which cannot be adjusted, you can add your own image view

CGRect frame = CGRectMake(xOffset, yOffset, width, height);

UIImageView *imgView = [UIImageView.alloc initWithFrame:frame];
[cell addSubview:imgView];

Then use your same code to configure imgView instead of cell.imgView, and you can customize imgView however you need!

Lytic
  • 786
  • 5
  • 12
  • What I did was create a custom tableView cell but I'll give you the correct answer since that works as well, thank you. – WokerHead Oct 17 '16 at 03:14