macOS/iOS API解説

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

目次

setTemporaryAttributes:forCharacterRange:

一時的な文字属性をセットします
-(void)setTemporaryAttributes:(NSDictionary *)attrs:
                 forCharacterRange:(NSRange)charRange:

解説

一時的な文字属性をセットします。
【attrsの要素】文字属性名の辞書の要素
● NSForegroundColorAttributeName 描画カラー
● NSUnderlineStyleAttributeName 下線

返り値

( void )

なし

引数

( NSDictionary * )attrs
( NSRange )charRange

フレームワーク

ApplicationKit

クラス

NSLayoutManager

Instance Methods

使用可能

10.0

参照

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)add:(id)sender
{
//myOutletはTextView
NSLayoutManager *layM;
NSDictionary *dic = 
[NSDictionary dictionaryWithObjectsAndKeys:
    [NSColor redColor],NSForegroundColorAttributeName,
   nil];
    
layM = [myOutlet layoutManager];

NSLog([[layM firstTextView] className]);
[[layM firstTextView] insertText:@"the red text"];

[layM setTemporaryAttributes:dic
                        forCharacterRange:NSMakeRange(4,3)
                        ];
}

- (IBAction)remove:(id)sender
{
NSLayoutManager *layM;    
layM = [myOutlet layoutManager];


[layM removeTemporaryAttribute:NSForegroundColorAttributeName
        forCharacterRange:NSMakeRange(4,3)
                        ];

}


@end