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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:10:38+00:00 2026-05-24T12:10:38+00:00

I am drawing a string in a UIView using -drawRect:. This string may contain

  • 0

I am drawing a string in a UIView using -drawRect:. This string may contain links and I would like to make these links a different color and make them clickable.

Does anyone know the best (and easiest) way to do this? I am fearing that I will have to filter the links out of the string, create buttons for the links and then position the different parts of the string including the buttons manually.

This is my code in -drawRect:

NSString *message = [cellData objectForKey:@"message"];
CGSize messageLabelSize = [sizeCalc sizeOfMessageLabel:message];
[message drawInRect:CGRectMake(kBoxPadding + kProfilePicWidth + kBoxPadding, kBoxPadding + nameLabelSize.height + kSpacingNameToMessage - kContentOffset, messageLabelSize.width, messageLabelSize.height) withFont:[UIFont fontWithName:@"Helvetica" size:13]];

My message string could look like this:

“This is a test text and it has a link http://google.com/ in the
middle.”

I would like the result to look a bit like the above where http://google.com/ is a hyperlink.

  • 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-24T12:10:40+00:00Added an answer on May 24, 2026 at 12:10 pm

    You can’t from a drawRect because that just draw graphics, you need a subview:

    NSString *message = @"This is a test text and it has a link http://google.com/ in the middle.";
    CGSize size = [message sizeWithFont:[UIFont boldSystemFontOfSize:11.0]]
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake (0, 0, size.width, size.height)]; 
    textVioew.editable = NO;
    [textView setDataDetectorTypes:UIDataDetectorTypeLink];
    [textView setText:message];
    [self.view addSubview:textView];
    [textView release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In VB.NET I'm drawing an ellipse using some code like this. aPen = New
I'm using Json.NET First look at this: using System.Drawing; string json = JsonConvert.SerializeObject(new Rectangle(-3,6,32,32),
I'm using System.Drawing.Color, is there anything in Visual Studio that can display the color
can someone please give me a c# example of drawing a string using GDI+
When I try to save an image using either System.Drawing.Image.Save(String) or System.Drawing.Bitmap.Save(String) an exception
I create a table in j2me.Using javax.microedition.lcdui.CustomItem by drawing lines & placing a string.Then
This may seem like a fairly basic question, for which I apologise in advance.
System.Drawing.Color objects apparently won't serialize with XmlSerializer. What is the best way to xml
I'm working on drawing an SVG grid using Javascript. I've managed to get the
I have some logic, which defines and uses some user-defined types, like these: class

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.