Search code examples
iphoneobjective-cuitableviewsubviews

objective c- adding few subviews to a UITableViewCell


I have a UITableView that displays images, but I want some text to be displayed above and under every image.

when I add text it's being displayed in the center behind the image.

how can I programmatically control the position of subviews in my cell ? (the number of cell changes during the program at runtime)

thanks


Solution

  • inside cellForRowAtIndexPath add your text as subviews (e.g. x= 10, y = 20, width = 200, height = 100) :

    myText = [[UITextView alloc] initWithFrame:CGRectMake(10, 20, 200, 100)];
    myText.text = @" some text here";
    [self addSubview:myText];
    

    to bring the text to the front:

    [self bringSubviewToFront:myText];