Clickable URLs in a UITextView
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