macOS/iOS API解説

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

目次

-attribute:atIndex:longestEffectiveRange:inRange:

INDEX>Foundation>NSAttributedString

属性名と番号で属性と適用される範囲を返します
-(id)attribute:(NSString *)attributeName:
             atIndex:(unsigned int)index:
             longestEffectiveRange:(NSRangePointer)aRange:
             inRange:(NSRange)rangeLimit:

解説

属性名と番号で属性と適用される範囲を返します。
【attributeName】属性名 OS X

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? 文字シェイプ
NSGlyphInfoAttributeName   グリフ情報(10.2-)

【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

適用される範囲のポインタ

( NSRange )rangeLimit

最大の範囲

クラス

NSAttributedString

Instance Methods

使用可能

10.0
iOS3.2

参照

- attribute:atIndex:longestEffectiveRange:inRange:

例文

#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 
                    longestEffectiveRange:&bRange
                    inRange:NSMakeRange(0,5)
                    ]
                     description]);
NSLog([NSString stringWithFormat:@"%d,%d",bRange.location,bRange.length]);
}
}
@end