WebViewなしでリンク付きのテキストを描画してくれる、CoreTextHyperlinkView。
長押しでコピーもできる。最高。
CoreTextHyperlinkViewはBSDライセンス、中で使われているAutoHyperlinksはnew BSDライセンスです。
WebViewを使わずにリンク付きテキスト
サンプル
書くまでもない程簡単。HTMLの方が難しいレベル。
NSString* text = @"URLが含まれる文章";
textView = [[[JSCoreTextView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)] autorelease];
[textView setText:text];
ただ、長い文章はUIScrollViewのsubviewにする必要がある。
CGFloat height = [JSCoreTextView measureFrameHeightForText:text
fontName:font
fontSize:size
constrainedToWidth:_textView.frame.size.width - (paddingLeft * 2)
paddingTop:paddingTop
paddingLeft:paddingLeft];
CGRect textFrame = [_textView frame];
textFrame.size.height = height;
[_textView setFrame:textFrame];
[_scrollView addSubview:_textView];
フォントなんかの変更はUILabelとかと同じ。
ちなみに、JSTwitterCoreTextViewを使うと、JSCoreTextViewの機能に加えて @以降をユーザー名、#以降をハッシュタグへのリンクにしてくれるというおまけ付き。
