Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 06-04-2008, 06:29 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2008
Posts: 22
satyanarayanagv is an unknown quantity at this point
Default How to Wrap Text in UITableViewCell ?

Hi,

We have large text which is to be displayed in a UITableViewCell .
We need to view the entire text in the cell but it displays some part of the text with "..." at the ending. Can any one suggest the relevant approach to wrap text in our customized UITableViewCell?
or else Is there any option to display Tooltip on touching UITableViewcell of UITableView in iphone SDK?

Thanks
Satya
satyanarayanagv is offline   Reply With Quote
Old 06-04-2008, 06:48 AM   #2 (permalink)
New Member
 
Join Date: May 2008
Posts: 22
fasttech is an unknown quantity at this point
Default Re: How to Wrap Text in UITableViewCell ?

I have a two line text area for my table rows. Here is how I did it (though I did some fudging with absolute pixel values for offsets):
Code:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    
    CGRect contentRect = CGRectMake(80.0, 0.0, 240, 40);
    UILabel *textView = [[UILabel alloc] initWithFrame:contentRect];
	
	textView.text = mytext;
	textView.numberOfLines = 2;
	textView.textColor = [UIColor grayColor];
	textView.font = [UIFont systemFontOfSize:12];
        [cell.contentView addSubview:textView];
	[textView release];
I have this code in the cellForRowAtIndexPath method for the tableView delegate. myText is the long text that wraps.
fasttech is offline   Reply With Quote
Old 06-04-2008, 08:40 AM   #3 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 298
javid.alimohideen is an unknown quantity at this point
Default Re: How to Wrap Text in UITableViewCell ?

Let's assume you are using a UILabel to display the text in the UITableViewCell. You can calculate the size of the table cell by using the code below:

Code:
-(CGSize) GetSizeOfText: (NSString *) text {
  return [text sizeWithFont:[UIFont systemFontOfSize:17.0
                                                     constrainedToSize:CGSizeMake(220.f, 50.0f)]];
}
Use the above functiona to calculate the frame for the table view cell and use it to initialize the cell

Hope it helps,

Thanks,
Javid
javid.alimohideen is offline   Reply With Quote
Old 06-05-2008, 01:37 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2008
Posts: 22
satyanarayanagv is an unknown quantity at this point
Default Re: How to Wrap Text in UITableViewCell ?

Quote:
Originally Posted by fasttech
I have a two line text area for my table rows. Here is how I did it (though I did some fudging with absolute pixel values for offsets):
Code:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }
    
    CGRect contentRect = CGRectMake(80.0, 0.0, 240, 40);
    UILabel *textView = [[UILabel alloc] initWithFrame:contentRect];
	
	textView.text = mytext;
	textView.numberOfLines = 2;
	textView.textColor = [UIColor grayColor];
	textView.font = [UIFont systemFontOfSize:12];
        [cell.contentView addSubview:textView];
	[textView release];
I have this code in the cellForRowAtIndexPath method for the tableView delegate. myText is the long text that wraps.
Thanks
satyanarayanagv is offline   Reply With Quote
Old 06-05-2008, 01:40 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2008
Location: Colorado
Posts: 312
jonc is an unknown quantity at this point
Send a message via AIM to jonc
Default Re: How to Wrap Text in UITableViewCell ?

Quote:
Originally Posted by javid.alimohideen
Let's assume you are using a UILabel to display the text in the UITableViewCell. You can calculate the size of the table cell by using the code below:

Code:
-(CGSize) GetSizeOfText: (NSString *) text {
  return [text sizeWithFont:[UIFont systemFontOfSize:17.0
                                                     constrainedToSize:CGSizeMake(220.f, 50.0f)]];
}
Use the above functiona to calculate the frame for the table view cell and use it to initialize the cell

Hope it helps,

Thanks,
Javid

What is the 'f' character for in CGSizeMake?
jonc is offline   Reply With Quote
Old 06-05-2008, 08:34 AM   #6 (permalink)
New Member
 
Join Date: Apr 2008
Posts: 298
javid.alimohideen is an unknown quantity at this point
Default Re: How to Wrap Text in UITableViewCell ?

It just says it's a float.
javid.alimohideen is offline   Reply With Quote
Old 08-14-2008, 01:27 PM   #7 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 28
ae6rt is on a distinguished road
Default

This technique was very helpful, as I struggled with the same problem.

What technique can one use to make hyperlinks click-able in this UILabel view?
ae6rt is offline   Reply With Quote
Old 12-16-2009, 05:05 AM   #8 (permalink)
Registered Member
 
Join Date: Dec 2009
Location: Pune
Posts: 1
pravara is on a distinguished road
Default

Hi,
I have implemented the same method to display text in the UITableView.
My issue is the contents of all the rows of th table view are different.
So can i have labels of varying sizes in UITableViewCell?


or can I use UIView instead of lable in UITableViewCell? so that i can have scroll bars to display data.
pravara is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UITableViewCell: possibly a bug javid.alimohideen iPhone SDK Development 7 10-26-2009 12:21 PM
uitableviewcell.. make text transparent? turinreza iPhone SDK Development 7 09-09-2009 12:17 PM
UITextView with word wrap? halusha iPhone SDK Development 3 07-06-2008 02:36 AM
Adding button and text field in uitableviewcell sasikantpradeep iPhone SDK Development 1 06-06-2008 07:55 AM
UITableViewCell accessoryView brianr iPhone SDK Development 1 05-23-2008 10:03 AM


» Advertisements
» Online Users: 337
2 members and 335 guests
guusleijsten, LEARN2MAKE
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:43 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0