Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6831889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:47:28+00:00 2026-05-26T22:47:28+00:00

I wish to render text on a large amount of UITableViewCell’s. The text is

  • 0

I wish to render text on a large amount of UITableViewCell’s.
The text is rendered in a UITableViewCells drawRect:(CGRect)rect method.

Each cell contains a different number of lines and the text has attributes like weight and color.

In - (void) tableview:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath;
I pass the tableViewCell the attributedString, which I pre made when building my model.
I attached some code that shows the gist of what goes on in my drawRect.

I keep reading (documentation, blogs etc.) that the CTFrameSetter is the most expensive object to create. This makes sense as this is were all the calculations for the glyphs and runs are calculated. My question now is, can I pre make this as well and pass it to my cell
on cellForRowAtIndexPath and is it likely to have a positive effect on speed?

- (void) drawRect:(CGRect)rect
{   
/* These are pre-populated and the attributedString is passed to the cell at run time

    NSDictionary *stringAttributeDict = [NSDictionary dictionaryWithObjectsAndKeys:
                         (id)fontRef, (NSString*)kCTFontAttributeName, 
                         (id)[[UIColor blueColor] CGColor], (NSString*)(kCTForegroundColorAttributeName), nil]];
    NSDictionary *firstPartAttributeDict = [NSDictionary dictionaryWithObjectsAndKeys:
                          (id)fontRef, (NSString*)kCTFontAttributeName, 
                          (id)[[UIColor greenColor] CGColor], (NSString*)(kCTForegroundColorAttributeName), nil]];

    [attributedString addAttributes:stringAttributeDict range:NSMakeRange(0, [attributedString.string length])];
    [attributedString addAttributes:firstPartAttributeDict range:NSMakeRange(0, 5)];

*/
    rect = CGRectInset(rect, 5.0, 5.0);

    CGContextRef context = UIGraphicsGetCurrentContext();

    // Flip the coordinate system
    CGContextSetTextMatrix(context, CGAffineTransformIdentity);
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    //Make a path to render the text in
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, rect);

    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedString);
    CTFrameRef theFrame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attributedString length]), path, NULL);
    CFRelease(framesetter);
    CFRelease(path);

    //Draw the text:
    CTFrameDraw(theFrame, context);
    CFRelease(theFrame);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:47:29+00:00Added an answer on May 26, 2026 at 10:47 pm

    Yes, you should be able to keep it around and share it between cells. I have kept a persistent CTFramesetterRef around for multiple text blocks inside of a single view, I can’t see why using it for multiple cells in a tableview would be any different.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large database of XHTML that I wish to render as PDFs
I have some XML text that I wish to render in an HTML page.
I have a large amount of data I wish to use with Jquery DataTable
I wish to render a scene that contains one box and a point light
Lets say I wish to be able to render different view logic for two
I wish to copy the top 1000 lines in a text file containing more
I wish to add a singleton method to a particular object. I wish that
I wish to off-screen render a Control to some bitmap so that I have
I'm rendering simple scene with library GLESv1_CM on Android with NDK. void render(Rect viewport)
I have a page where I wish to render the following html (a small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.