macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

initWithHTML:documentAttributes:

HTMLデータから属性付き文字列を作って返します
-(id)initWithHTML:(NSData *)data:
           documentAttributes:(NSDictionary **)docAttributes:

解説

HTMLデータから属性付き文字列を作って返します。
文書属性を辞書で返します。
データを読むことができなければnilを返します。

返り値

( id )

文字列

引数

( NSData * )data

データ

( NSDictionary ** )docAttributes

文書属性のポインタ

フレームワーク

ApplicationKit

クラス

NSAttributedStringAdditions

Instance Methods

使用可能

10.1

参照

例文

#import "SetImage.h"

@implementation SetImage

- (IBAction)set:(id)sender
{
NSAttributedString *aString;
NSData *dat;
NSDictionary *dic;
   //開けるファイル拡張子の配列
    NSArray      *fileTypes    = [ NSArray arrayWithObject : @"html" ];
    //OpenPanelを作る
    NSOpenPanel  *opPanel       = [ NSOpenPanel openPanel ];
    //OpenPanelの結果のボタン番号
    int		  opRet;
     
        //OpenPanelでファイル選択   
    opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか
                                     file : @"Documents" //どのファイルを選択しておくか
                                    types : fileTypes ];//選べるファイルタイプ

    if ( opRet == NSOKButton ) {  // OPENPanelのボタンがOKなら
        dat = [NSData dataWithContentsOfFile: [opPanel filename] ];
        aString = [[NSAttributedString allocWithZone:[self zone]] initWithHTML:dat documentAttributes:&dic];
        [name setAttributedStringValue:aString];
        
        NSLog([dic description]);
    }

        


}

@end