• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Clickable URLs in a UITextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Clickable URLs in a UITextView


  • Subject: Clickable URLs in a UITextView
  • From: DKJ <email@hidden>
  • Date: Sun, 4 Oct 2009 08:08:48 -0700

I've subclassed a UITextView, and I want it to display clickable URLs. I put the URL string in the view using its drawRect: method. But when the view is displayed, the URL isn't clickable. Here's the code I'm using:


- (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.editable = NO; self.userInteractionEnabled = YES; self.dataDetectorTypes = UIDataDetectorTypeAll; } return self; }

- (void)drawRect:(CGRect)rect
{
	CGRect r = CGRectMake(20, 20, 280, 30);
	NSString *line = @"http://www.erewhon.org";;
	[line drawInRect:r
		withFont:[UIFont systemFontOfSize:18.0]
		lineBreakMode:UILineBreakModeWordWrap
		alignment:UITextAlignmentCenter];
	}
}

Why don't I get a clickable URL in this view?

Rather than simply setting the view's text property, I'm doing it this way so I can have different fonts in different lines. No doubt this is why the dataDetectorTypes setting isn't doing what I want. But I'd be interested to know what's going on behind the scenes here. Is the string actually being displayed as a subview of the text view?

dkj
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Clickable URLs in a UITextView
      • From: Brent Gulanowski <email@hidden>
  • Prev by Date: Checking whether a file is a genuine PDF file
  • Next by Date: Re: Checking whether a file is a genuine PDF file
  • Previous by thread: Checking whether a file is a genuine PDF file
  • Next by thread: Re: Clickable URLs in a UITextView
  • Index(es):
    • Date
    • Thread