macOS/iOS API解説

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

目次

initWithString:attributes:

INDEX>Foundation>NSAttributedString

文字列と文字属性を表す辞書から、属性付き文字列を作って返します
-(id)initWithString:(NSString *)aString:
             attributes:(NSDictionary *)attributes:

解説

文字列と文字属性を表す辞書から、属性付き文字列を作って返します。

返り値

( id )

属性付き文字列

引数

( NSString * )aString

文字列

( NSDictionary * )attributes

属性

クラス

NSAttributedString

Instance Methods

使用可能

10.0
iOS3.2

参照

-initWithRTF:documentAttributes:(NSAttributedString Additions)

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
NSAttributedString *aString;

aString = [[[NSAttributedString alloc] initWithString:@"string" attributes:[self boldFontAttributes]] autorelease];
      
 [image lockFocus];
[aString drawAtPoint:NSMakePoint(0,1)];
 [image unlockFocus];
}
- (NSDictionary*)boldFontAttributes
 {
    return [NSDictionary dictionaryWithObject: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]] forKey:NSFontAttributeName];
}

@end