Amit Hagin
Amit Hagin

Reputation: 3236

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

Upvotes: 0

Views: 657

Answers (3)

Oded Regev
Oded Regev

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

ader
ader

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

mattjgalloway
mattjgalloway

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

Related Questions