attribute:atIndex:effectiveRange:
INDEX>Foundation>NSAttributedString
属性名と番号で属性と適用される範囲を返します
-(id)attribute:(NSString *)attributeName: atIndex:(unsigned int)index: effectiveRange:(NSRangePointer)aRange:
解説
属性名と番号で属性と適用される範囲を返します。
【attributeName】属性名
● NSFontAttributeName フォント属性(NSFont)
● NSParagraphStyleAttributeName 段落スタイル(NSParagraphStyle)
● NSForegroundColorAttributeName 描画色(NSColor, default blackColor)
● NSUnderlineStyleAttributeName 下線(int)
● NSSuperscriptAttributeName スーパースクリプト(int)
● NSBackgroundColorAttributeName 背景色(NSColor)
● NSAttachmentAttributeName アタッチメント値(NSTextAttachment)
● NSLigatureAttributeName リガチャ値(int)
● NSBaselineOffsetAttributeName ベースラインオフセット値(float)
● NSKernAttributeName カーニング値(float)
● NSLinkAttributeName リンク
● NSCharacterShapeAttributeName 文字シェイプ(int?)
以下は10.2以降
● NSGlyphInfoAttributeName グリフ情報
【name】文字属性名 iOS
NSFontAttributeName | UIFont | フォント名 |
NSParagraphStyleAttributeName | NSParagraphStyle | 段落スタイル |
NSForegroundColorAttributeName | UIColor | 描画カラー |
NSUnderlineStyleAttributeName | NSNumber | 下線 |
NSSuperscriptAttributeName | 上付き | |
NSBackgroundColorAttributeName | UIColor | 背景色 |
NSAttachmentAttributeName | テキストアタッチメント | |
NSLigatureAttributeName | NSNumber | リガチャ |
NSBaselineOffsetAttributeName | ベースラインシフト | |
NSKernAttributeName | floatのNSNumber | カーニング |
NSLinkAttributeName | リンク | |
NSStrikethroughStyleAttributeName | NSNumber | 取り消し線のスタイル |
NSStrikethroughColorAttributeName | UIColor | 取り消し線のカラー |
NSString *const NSFontAttributeName;
NSString *const NSParagraphStyleAttributeName;
NSString *const NSForegroundColorAttributeName;
NSString *const NSBackgroundColorAttributeName;
NSString *const NSLigatureAttributeName;
NSString *const NSKernAttributeName;
NSString *const NSStrikethroughStyleAttributeName;
NSString *const NSUnderlineStyleAttributeName;
NSString *const NSStrokeColorAttributeName;
NSString *const NSStrokeWidthAttributeName;
NSString *const NSShadowAttributeName;
NSString *const NSTextEffectAttributeName;
NSString *const NSAttachmentAttributeName;
NSString *const NSLinkAttributeName;
NSString *const NSBaselineOffsetAttributeName;
NSString *const NSUnderlineColorAttributeName;
NSString *const NSStrikethroughColorAttributeName;
NSString *const NSObliquenessAttributeName;
NSString *const NSExpansionAttributeName;
NSString *const NSWritingDirectionAttributeName;
NSString *const NSVerticalGlyphFormAttributeName;
返り値
( id )
属性
引数
( NSString * )attributeName
属性名
( unsigned int )index
番号
( NSRangePointer )aRange
適用される範囲のポインタ
フレームワーク
Foundation
クラス
NSAttributedString
Instance Methods
使用可能
10.0
参照
- attribute:atIndex: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 attribute:NSParagraphStyleAttributeName atIndex:1 effectiveRange:&bRange ] description]); NSLog([NSString stringWithFormat:@"%d,%d",bRange.location,bRange.length]); } } @end