WebKit を用いて HTML 文字列を描画する
NSAttributedString を用いれば HTML 文字列を HTML として解釈して描画してくれます。基本形はこれ。
// NSAttributedString -(id) initWithHTML:(NSData*)data options:(NSDictionary*)options documentAttributes:(NSDictionary**)dict
10.4以降なら自動的に WebKit を用いた描画になりますが、10.3なら WebKit の使用を明示する必要 (*) があります。で、この options でいろいろできちゃうんです。例えば WebPrefereces の設定とか、エンコーディングの指定とか。いくつかあげておきましょう。
10.4のみ使えるキー | 10.3でも使えるキー | 概要 |
---|---|---|
NSCharacterEncoding DocumentOption |
@"CharacterEncoding" | エンコーディング |
NSWebPreferences DocumentOption |
@"WebPreferences" | WebPreferences |
NSWebResourceLoadDelegate DocumentOption |
@"WebResourceLoadDelegate" | WebResourceLoadDelegateオブジェクト |
@"UseWebKit" | 10.3で WebKit を使うのに必須 (*) |