Geometry 関数
NSBundle
NSDictionary
NSFileManager
NSMutableAttributedString
NSNumber
NSScanner
NSString
NSTimer
Graphic 関数
NSApplication
NSBezierPath
NSCell
NSColor
NSCursor
NSCustomImageRep
NSDocument
NSDocumentController
NSDragging
NSEvent
NSFontManager
NSGraphicsContext
NSImage
NSMenu
NSOutlineView
NSPanel
NSPopUpButton
NSResponder
NSScrollView
NSString 追加
-NSString を画面にかく
NSTableColumn
NSTableView
NSTextStorage
NSTextView
NSToolbar
NSView
NSWindow
NSWorkspace
その他
.nib ウィンドウ
Views パレット
クラス
インスタンス変数
メソッド
CFXML
Carbon Event
Carbon Graphics
Cocoa で日本語
メソッド
その他

- Application Kit-
NSString 追加

Application Kit - NSString 追加
NSString を画面にかく
Keywords: drawAtPoint, drawInRect

ある文字列を画面に描くにはどうしたらいいのか?NSString Addisions で定義されている、drawAtPoint:withAttributes:drawInRect:withAttributes: で書くことができるんだ:

Application Kit/NSStringDrawing.h
- (void)drawAtPoint:(NSPoint)point 
        withAttributes:(NSDictionary *)attrs;
- (void)drawInRect:(NSRect)rect 
        withAttributes:(NSDictionary *)attrs;

NSAttributedString を書くときは、withAttributes がなくなるよ。

Application Kit/NSStringDrawing.h
- (void)drawAtPoint:(NSPoint)point;
- (void)drawInRect:(NSRect)rect;

じゃあ、サンプルだ。

StringDrawingView.m (sample)
- (void)drawRect:(NSRect)rect
{
    NSMutableAttributedString* str;
    str = [[NSMutableAttributedString alloc]
            initWithString:@"Hello, NSString!"];
    NSPoint point = { 0, 0 };

    // 属性を設定する
    ...

    [str drawAtPoint:point];
}

これらの、NSString を描くメソッドは、NSView にフォーカスが当たっている状態で使わなきゃいけない。上のサンプルでは、NSView の drawRect: メソッドで呼び出しているので大丈夫だ。好きな属性を設定して、drawAtPoint: で、描いてくれ。



[Home] [Download] [Archives] [BBS] [Cocoa Programming Tips 1001] [Core Foundation の秘密] [Safari Developer Center] [はじめてのブラウザのつくり方] [Sketch BP] [スクリーンセイバーを作ろう] [Objective-C 最適化] [Authorization API 完全理解] [Mac OS X Programming Books Review] [オブジェクト指向の言語比較論] [panther-dev]

mailto: mkino@xd5.so-net.ne.jp