Reputation: 3236
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
Upvotes: 0
Views: 657
Reputation: 4405
First of all you should have mentioned if you are using a custom cell or not. in case it's the built-in cell that you are using, if you don't like the way it looks you should create a custom cell. see http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/
If you allready use a custom cell, my guess is that you didn't implement correctly the method
heightForRowAtIndexPath:
please check if a fix is needed...
Upvotes: 1
Reputation: 5393
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];
Upvotes: 2
Reputation: 34912
I would create a custom UITableViewCell
to be honest. Subclass it and add the views you want to its contentView
in its initialiser, then set it up as you wish for each cell in your table view data source.
Upvotes: 1