Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 1, 2008, 09:34 PM   #1
beachdog
macrumors member
 
Join Date: Aug 2008
Multiple text lines in a UITableView

I've done some basic programming of UITableViews, but now I have a need to create a table view with cells that contain multiple lines of text, preferably where each line may have a different Font size. I need to create something that looks like the table view in the "Inbox" view of the mail application. Can someone give me some pointers on this?
beachdog is offline   0 Reply With Quote
Old Sep 2, 2008, 04:20 AM   #2
Luke Redpath
macrumors 6502a
 
Join Date: Nov 2007
The first basic approach would be to create a UILabel for each individual text component needed and add these as subviews of the UITableViewCell, positioned appropriately.

You might find after doing this that your code is cleaner if you extract this into your own custom UITableViewCell subclass (especially if you intend to use it in more than one place).

The iPhone developer docs has a whole section on customizing table cells in the Table view programming guide.
Luke Redpath is offline   0 Reply With Quote
Old Sep 2, 2008, 04:35 PM   #3
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
If each line in each cell can have a different font then you need a separate Label for each line. If each cell has multiple lines but each cell has only a single font then you can use a single Label in each cell. You don't actually say if all the cells have the same number of lines or if they vary. If they are all the same then just look at the docs and examples. There are several that show how to have multiple lines with different font characteristics.

If you have a variable number of lines you will need to use variable row heights. There is a tableview delegate callback, heightForRowAtIndexPath, that allows you to tell the table the row height for each cell. You will need to calculate the rowheight using NSString:sizeWithFont:constrainedToSize:lineBreakMode:, which isn't as much fun as it sounds. Unfortunately I couldn't figure out a way to determine the width of the cell for certain. What I do is get the width of the screen (320 or 480 depending on orientation) and subtract a factor that I determined emperically from that width. I have a label in my cell so my width won't work for you. Try different widths until you get one that gives you the correct height for your text.
PhoneyDeveloper is offline   0 Reply With Quote
Old Mar 12, 2009, 04:58 AM   #4
iphonejudy
macrumors 6502
 
Join Date: Sep 2008
Quote:
Originally Posted by beachdog View Post
I've done some basic programming of UITableViews, but now I have a need to create a table view with cells that contain multiple lines of text, preferably where each line may have a different Font size. I need to create something that looks like the table view in the "Inbox" view of the mail application. Can someone give me some pointers on this?
Have you got the solution?if,Please let me know
__________________
Judy
iphonejudy is offline   0 Reply With Quote
Old Mar 12, 2009, 06:17 AM   #5
sujithkrishnan
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
Multiline text in UITableViewCell

Are u trying to do something like in the given attached file.If so then create custom view,in draw rect of it draw string.And cell height should be the height of string that u want to display.Custom view should be added as subView to cell.contentView.If u are trying to do something like this,then i can give u code.
Attached Images
 

Last edited by sujithkrishnan; Mar 13, 2009 at 01:50 AM.
sujithkrishnan is offline   0 Reply With Quote
Old Mar 12, 2009, 06:40 AM   #6
iphonejudy
macrumors 6502
 
Join Date: Sep 2008
Quote:
Originally Posted by sujithkrishnan View Post
Are u trying to do something like in the given attached file.If so then create custom view,in draw rect of it draw string.And cell height should be the height of string that u want to display.Custom view should be added as subView to cell.contentView.If u are trying to do something like this,then i can give u code.
Ya suji.I want like this
__________________
Judy
iphonejudy is offline   0 Reply With Quote
Old Mar 12, 2009, 12:12 PM   #7
fenrus110
macrumors regular
 
Join Date: Mar 2008
it's just customizing the UITableViewCell. There are a lot of examples of how to do this around already.

http://blog.atrexis.com/index.cfm/20...ITableCellView
http://iphone.zcentric.com/2008/08/0...tableviewcell/
fenrus110 is offline   0 Reply With Quote
Old Mar 12, 2009, 01:06 PM   #8
North Bronson
macrumors 6502
 
Join Date: Oct 2007
Location: Los Angeles
Quote:
Originally Posted by PhoneyDeveloper View Post
Unfortunately I couldn't figure out a way to determine the width of the cell for certain. What I do is get the width of the screen (320 or 480 depending on orientation) and subtract a factor that I determined emperically from that width.
I had this problem and I ended up using this:

Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
	CustomCell *selectedCustomCell = (CustomCell *)[tableView cellForRowAtIndexPath: indexPath];

	UIView *selectedContentView = [selectedCustomCell contentView];

	CGRect selectedBounds = selectedContentView.bounds;

	NSLog (@"Origin x: %@: selectedBounds.origin.x);

	NSLog (@"Origin y: %@: selectedBounds.origin.y);

	NSLog (@"Size width: %@: selectedBounds.size.width);

	NSLog (@"Size height: %@: selectedBounds.size.height);

//	More code
}
This should pop out the dimensions of any cell you touch. You can see that if you have an accessory (like a check-mark or a chevron) the size adjusts accordingly.
__________________
North Bronson Software
North Bronson is offline   0 Reply With Quote
Old Mar 13, 2009, 01:18 AM   #9
iphonejudy
macrumors 6502
 
Join Date: Sep 2008
I need to display the rss fields in tableview ,So i cant use your above technique
__________________
Judy
iphonejudy is offline   0 Reply With Quote
Old Mar 13, 2009, 03:32 AM   #10
caveman_uk
Guest
 
caveman_uk's Avatar
 
Join Date: Feb 2003
Location: Hitchin, Herts, UK
Use this method from NSString to get the height of a string
Code:
- (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(UILineBreakMode)lineBreakMode
None of the others (AFAIK) actually do wrapping except this one

Link
caveman_uk is offline   0 Reply With Quote
Old Mar 13, 2009, 10:34 AM   #11
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by iphonejudy View Post
I need to display the rss fields in tableview ,So i cant use your above technique
Because rss data is different than other kinds of text?
dejo is online now   0 Reply With Quote
Old May 11, 2009, 11:13 PM   #12
acjrocks
macrumors member
 
Join Date: Mar 2008
Quote:
Originally Posted by sujithkrishnan View Post
Are u trying to do something like in the given attached file.If so then create custom view,in draw rect of it draw string.And cell height should be the height of string that u want to display.Custom view should be added as subView to cell.contentView.If u are trying to do something like this,then i can give u code.
Still have the source for this? I sure could use this. Still learning about custom table views and cells.
acjrocks is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How do I create a compound path or clipping mask for text in front of lines in AI patent10021 Design and Graphics 6 Nov 19, 2013 12:52 AM
Creating a String with multiple lines LT21j iPhone/iPad Programming 5 Jun 6, 2013 09:50 AM
Sorting lines of text, not alphabetically, but buy value ($$)... madsylar Mac Programming 4 Apr 8, 2013 07:05 AM
Ugh!!! Does half wonky cursor in text lines indicate bad RAM??!! isaiah41v10 Mac mini 5 Mar 19, 2013 01:53 PM
Three Lines Of Text For Filenames In Finder steiney Mac Applications and Mac App Store 12 Oct 28, 2012 10:37 AM

Forum Jump

All times are GMT -5. The time now is 09:24 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC