macOS/iOS API解説

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

目次

addAttribute:value:range:

変更可能な属性付き文字列に文字の属性(フォント、サイズ、カラーなど)を付加します
-(void)addAttribute:(NSString *)name:
             value:(id)value:
             range:(NSRange)aRange:

解説

変更可能な属性付き文字列に文字の属性(フォント、サイズ、カラーなど)を付加します。
名(name)または値(value)がnilならNSInvalidArgumentExceptionを起こします。
範囲(aRange)がレシーバの範囲を越えたらNSRangeExceptionを起こします。
【name】文字属性名 OS X

NSFontAttributeName NSFont フォント名
NSParagraphStyleAttributeName NSParagraphStyle 段落スタイル
NSForegroundColorAttributeName NSColor 描画カラー
NSUnderlineStyleAttributeName   下線
NSSuperscriptAttributeName   上付き
NSBackgroundColorAttributeName   背景色
NSAttachmentAttributeName   テキストアタッチメント
NSLigatureAttributeName   リガチャ
NSBaselineOffsetAttributeName   ベースラインシフト
NSKernAttributeName   カーニング
NSLinkAttributeName   リンク

【name】文字属性名 iOS

NSFontAttributeName UIFont フォント名
NSParagraphStyleAttributeName NSParagraphStyle 段落スタイル
NSForegroundColorAttributeName UIColor 描画カラー
NSUnderlineStyleAttributeName NSNumber 下線
NSSuperscriptAttributeName   上付き
NSBackgroundColorAttributeName UIColor 背景色
NSAttachmentAttributeName   テキストアタッチメント
NSLigatureAttributeName NSNumber リガチャ
NSBaselineOffsetAttributeName   ベースラインシフト
NSKernAttributeName floatのNSNumber カーニング
NSLinkAttributeName   リンク
NSStrikethroughStyleAttributeName NSNumber 取り消し線のスタイル
NSStrikethroughColorAttributeName UIColor 取り消し線のカラー

NSString *const NSFontAttributeName;
NSString *const NSParagraphStyleAttributeName;
NSString *const NSForegroundColorAttributeName;
NSString *const NSBackgroundColorAttributeName;
NSString *const NSLigatureAttributeName;
NSString *const NSKernAttributeName;
NSString *const NSStrikethroughStyleAttributeName;
NSString *const NSUnderlineStyleAttributeName;
NSString *const NSStrokeColorAttributeName;
NSString *const NSStrokeWidthAttributeName;
NSString *const NSShadowAttributeName;
NSString *const NSTextEffectAttributeName;
NSString *const NSAttachmentAttributeName;
NSString *const NSLinkAttributeName;
NSString *const NSBaselineOffsetAttributeName;
NSString *const NSUnderlineColorAttributeName;
NSString *const NSStrikethroughColorAttributeName;
NSString *const NSObliquenessAttributeName;
NSString *const NSExpansionAttributeName;
NSString *const NSWritingDirectionAttributeName;
NSString *const NSVerticalGlyphFormAttributeName;

返り値

( void )

なし

引数

( NSString * )name

名前

( id )value

( NSRange )aRange

範囲

クラス

NSMutableAttributedString

Instance Methods

使用可能

10.0

参照

- addAttributes:range:
- removeAttribute: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])];
            
[myOutlet setAttributedStringValue:maStr];
}
- (NSDictionary*)boldFontAttributes {
    return [NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
}
@end

3種類の日本教 日本人が気づいていない自分の属性 (講談社プラスアルファ新書)

3種類の日本教 日本人が気づいていない自分の属性 (講談社プラスアルファ新書)