attributesAtIndex:effectiveRange:
INDEX>Foundation>NSAttributedString
属性付き文字列の属性の番号で指定してその文字属性を辞書で返します
-(NSDictionary *)attributesAtIndex:(unsigned)index: effectiveRange:(NSRangePointer)aRange:
解説
属性付き文字列の番号(index)で指定してその文字属性を辞書で返します。
範囲(aRange)のポインタにはその属性の範囲が返されます。
番号が属性付き文字列の属性の数より多ければNSRangeExceptionを起こします。
返り値
( NSDictionary * )
文字属性辞書
引数
( unsigned )index
番号
( NSRangePointer )aRange
範囲
フレームワーク
Foundation
クラス
NSAttributedString
Instance Methods
使用可能
10.0
iOS3.2
参照
- attributesAtIndex:effectiveRange:
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender {//開けるファイル拡張子の配列 NSArray *fileTypes = [ NSArray arrayWithObject : @"rtf" ]; //OpenPanelを作る NSOpenPanel *opPanel = [ NSOpenPanel openPanel ]; NSAttributedString *aString; //OpenPanelの結果のボタン番号 int opRet; NSRange bRange; //OpenPanelでファイル選択 opRet = [ opPanel runModalForDirectory : NSHomeDirectory() //どこのディレクトリを出すか file : @"Documents" //どのどのファイルを選択しておくか types : fileTypes ];//選べるファイルタイプ if ( opRet == NSOKButton ) { // OPENPanelのボタンがOKなら aString = [[NSAttributedString allocWithZone:[self zone]] initWithPath:[opPanel filename] documentAttributes:NULL]; [image lockFocus]; [aString drawInRect:[image bounds]]; [image unlockFocus]; NSLog([[aString attributesAtIndex:1 effectiveRange:&bRange] description]); NSLog([NSString stringWithFormat:@"%d,%d",bRange.location,bRange.length]); } } @end