macOS/iOS API解説

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

目次

removeAttribute:range:

変更可能な属性付き文字列にからnameで指定される文字属性を削除します
-(void)removeAttribute:(NSString *)name:
             range:(NSRange *)aRange:

解説

変更可能な属性付き文字列にからnameで指定される文字属性を削除します。
範囲(aRange)がレシーバの範囲を越えればNSRangeExceptionを返します。

返り値

( void )

なし

引数

( NSString * )name

名前

( NSRange * )aRange

範囲

クラス

NSMutableAttributedString

Instance Methods

使用可能

10.0

参照

- addAttribute:value:range:
- addAttributes:range:

例文

#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 addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(0, [maStr length])];

//取り除く
[maStr removeAttribute:NSForegroundColorAttributeName range:NSMakeRange(3,7)];

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