macOS/iOS API解説

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

目次

replaceCharactersInRange:withString:

変更可能な属性付き文字列の指定した範囲を文字列に置き換えます
-(void)replaceCharactersInRange:(NSRange)aRange:
          withString:(NSString *)aString:

解説

変更可能な属性付き文字列の指定した範囲(aRange)を文字列(aString)に置き換えます。
番号がレシーバの文字数より多ければNSRangeExceptionを起こします。

返り値

( void )

なし

引数

( NSRange )aRange

範囲

( NSString * )aString

文字列

クラス

NSMutableAttributedString

Instance Methods

使用可能

10.0

参照

- insertAttributedString:atIndex:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSMutableAttributedString *maStr =[[[NSMutableAttributedString alloc] initWithString:@"AttributedString" attributes:nil] autorelease];

//書体指定
[maStr addAttribute:NSFontAttributeName
            value:[NSFont fontWithName:@"Osaka" size:15.0]
            range:NSMakeRange(2,5)];
[maStr replaceCharactersInRange:NSMakeRange(3,5) withString:@"xxxx"];


[myOutlet setAttributedStringValue:maStr];
}
- (NSDictionary*)boldFontAttributes {
    return [NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
}
@end