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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:41:01+00:00 2026-06-05T13:41:01+00:00

I need to render rich text using Core Text in my view (simple formatting,

  • 0

I need to render rich text using Core Text in my view (simple formatting, multiple fonts in one line of texts, etc.). I am wondering if text rendered this way can be selected by user using (standard copy / paste function)?

  • 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-05T13:41:02+00:00Added an answer on June 5, 2026 at 1:41 pm

    I implemented a text selection in CoreText. It is really a hard work… But it’s doable.

    Basically you have to save all CTLine rects and origins using CTFrameGetLineOrigins(1), CTLineGetTypographicBounds(2), CTLineGetStringRange(3) and CTLineGetOffsetForStringIndex(4).

    The line rect can be calculated using the origin(1), ascent(2), descent(2) and offset(3)(4) as shown bellow.

    lineRect = CGRectMake(origin.x + offset, 
                          origin.y - descent, 
                          offset, 
                          ascent + descent);
    

    After doing that, you can test which line has the touched point looping the lines (always remember that CoreText uses inverse Y coordinates).

    Knowing the line that has the touched point, you can know the letter that is located at that point (or the nearest letter) using CTLineGetStringIndexForPosition.

    Here’s one screenshot.

    selecting text drawn with CoreText

    For that loupe, I used the code shown in this post.

    Edit:
    To draw the blue background selection, you have to paint the rect using CGContextFillRect. Unfortunately, there’s no background color in NSAttributedString.

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

Sidebar

Related Questions

I need to render some text with simple markup <b> <i> etc. and it
I need to render a line break using outputText so that I can utilize
I have a table that I need to render some vertical text in one
I'm working on a library that does some rich text abstraction using Core Text
I need to render some Rich Text in the screen that needs to change
I'm using Backbone.Marionette and need to render a view of employees and their respective
I need to render a partial view to a string within a controller action.
I'm writing a game in python with pygame and need to render text onto
I need to render a simple texture mapped model as the output of a
I need to render fonts into a 3d game world, so I use the

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.