macOS/iOS API解説

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

目次

replaceCharactersInRange:withAttributedString:

変更可能属性付き文字列の指定した範囲を属性付き文字列で入れ替えます
-(void)replaceCharactersInRange:(NSRange)aRange:
          withAttributedString:(NSAttributedString *)attributedString:

解説

変更可能属性付き文字列の指定した範囲を属性付き文字列で入れ替えます。
範囲がレシーバを越える場合はNSRangeExceptionを起こします。

返り値

( void )

なし

引数

( NSRange )aRange

入れ替える範囲

( NSAttributedString * )attributedString

属性付き文字列

クラス

NSMutableAttributedString

Instance Methods

使用可能

10.0

参照

- deleteCharactersInRange:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSMutableAttributedString *maStr =[[[NSMutableAttributedString alloc] initWithString:@"AttributedString" attributes:[self boldFontAttributes]] autorelease];
NSAttributedString *maStr2 =[[[NSMutableAttributedString alloc] initWithString:@"xxx" attributes:[self boldFontAttributes]] autorelease];

[maStr replaceCharactersInRange:NSMakeRange(2,5) withAttributedString:maStr2];
[myOutlet setAttributedStringValue:maStr];
}
- (NSDictionary*)boldFontAttributes {
    return [NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
}
@end