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 8924231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:21:17+00:00 2026-06-15T07:21:17+00:00

Possible Duplicate: UITextView : get text with wrap info I have been scouting the

  • 0

Possible Duplicate:
UITextView : get text with wrap info

I have been scouting the NSString library and numerous libraries for a function that can take a long string like this :

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui.

and together with a CGSize or float indicating the width, and the font being used, and return me a string with \n breaks and the words wrapped.

Result (roughly) :

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac\n
egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet.\n
 Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. \n
placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra.\n
 Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi.\n
 Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci,\n
 sagittis tempus lacus enim ac dui. 

I already know that UITextViews and such do this, but this is not helpful since I need to render the text in a raw OpenGL landscape, so I am using no regular UI elements.

I know this either exists as a framework, or a public class somewhere. I just simply can’t find any unified way of handling this.

I imagine it is close to [NSString sizeWithFont:forWidth:lineBreakMode:], but i do not need the size, I need the string itself.

  • 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-06-15T07:21:19+00:00Added an answer on June 15, 2026 at 7:21 am

    There really is no need to reinvent this wheel, since it is exactly what the text engine does for you every time you wrap text. And what is the text engine? It is Core Text. If you drop down to the level of Core Text and have a CTFramesetter lay out the text for you, you can learn where it is putting the line breaks by asking for the resulting CTLines.

    The documentation will get you started:

    http://developer.apple.com/library/ios/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Operations/Operations.html

    And there are lots of good tutorials on the Web.

    Simple example:

    NSString* s = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
    @"eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
    @"enim ad minim veniam, quis nostrud exercitation ullamco laboris "
    @"nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor "
    @"in reprehenderit in voluptate velit esse cillum dolore eu fugiat "
    @"nulla pariatur. Excepteur sint occaecat cupidatat non proident, "
    @"sunt in culpa qui officia deserunt mollit.";
    NSAttributedString* text = [[NSAttributedString alloc] initWithString:s];
    
    CTFramesetterRef fs =
    CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)text);
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddRect(path, NULL, CGRectMake(0,0,200,100000));
    CTFrameRef f = CTFramesetterCreateFrame(fs, CFRangeMake(0, 0), path, NULL);
    CTFrameDraw(f, NULL);
    
    NSArray* lines = (__bridge NSArray*)CTFrameGetLines(f);
    for (id aLine in lines) {
        CTLineRef theLine = (__bridge CTLineRef)aLine;
        CFRange range = CTLineGetStringRange(theLine);
        NSLog(@"%ld %ld", range.location, range.length);
    }
    CGPathRelease(path);
    CFRelease(f);
    CFRelease(fs);
    

    As you will see, the output shows the range of each line of wrapped text. Isn’t this the sort of thing you’re after?

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

Sidebar

Related Questions

Possible Duplicate: How to implement search function to UITextView? I have a UIViewContoller which
Possible Duplicate: How disable Copy, Cut, Select, Select All in UITextView I have some
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: How to call a JavaScript function from PHP? I have a php
Possible Duplicate: Getting detected data from the UITextView I have posted the same question
Possible Duplicate: Trying to get tables next to each other horizontal I have two
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: Unable to get a list of installed Python modules How do I

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.