insertAttributedString:atIndex:
変更可能な属性付き文字列の番号で指定する場所に別の属性付き文字列を挿入します
-(void)insertAttributedString:(NSAttributedString *)attributedString: atIndex:(unsigned)index:
解説
変更可能な属性付き文字列の番号(index)で指定する場所に別の属性付き文字列(attributedString)を挿入します。
番号がレシーバの文字数より多ければNSRangeExceptionを起こします。
返り値
( void )
なし
引数
( NSAttributedString * )attributedString
属性付き文字列
( unsigned )index
番号
フレームワーク
Foundation
クラス
NSMutableAttributedString
Instance Methods
使用可能
10.0
参照
- appendAttributedString:
+ attributedStringWithAttachment:(NSAttributedString)
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { NSMutableAttributedString *maStr =[[[NSMutableAttributedString alloc] initWithString:@"AttributedString" attributes:nil] autorelease]; NSMutableAttributedString *maStr2 =[[[NSMutableAttributedString alloc] initWithString:@"insertString" attributes:nil] autorelease]; //書体指定 [maStr addAttribute:NSFontAttributeName value:[NSFont fontWithName:@"Osaka" size:15.0] range:NSMakeRange(2,5)]; //描画色指定 [maStr2 addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(0, [maStr2 length])]; [maStr insertAttributedString:maStr2 atIndex:3]; [myOutlet setAttributedStringValue:maStr]; } - (NSDictionary*)boldFontAttributes { return [NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName]; } @end