macOS/iOS API解説

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

目次

init

レイアウトマネージャーを初期化して返します

解説

レイアウトマネージャーを初期化して返します。

返り値

( id )

NSLayoutManagerオブジェクト

引数

フレームワーク

ApplicationKit

クラス

NSLayoutManager

Instance Methods

使用可能

10.0

参照

- addLayoutManager:(NSTextStorage)
-addTextContainer:

例文

#import "MyObject.h"


@implementation MyObject
- (void)awakeFromNib {
	
	//1.テキストストレージを作る
		textStorage  = [[NSTextStorage alloc] init];
	
	//2.レイアウトマネージャーを作る
		layoutManager = [[MyLayoutManager alloc] init];
	
	//3.テキストストレージにレイアウトマネージャーを追加 3
		//今までのを削除
		id obj;
		NSEnumerator *aKeyEnumerator = [ [textStorage layoutManagers] objectEnumerator ];
		while (obj = [aKeyEnumerator nextObject]) {
			[textStorage removeLayoutManager: obj];
			}
	[textStorage addLayoutManager:layoutManager];
	
	//4.テキストコンテナ作成
	textContainerLeft = [[MyTextContainer alloc] initWithContainerSize:NSMakeSize(100,100)];
    
	
	//5.テキストビューにテキストコンテナをセット
	[textViewLeft replaceTextContainer:		textContainerLeft];
		
	//6.レイアウトマネージャーにテキストコンテナをセット
	[layoutManager addTextContainer:textContainerLeft];
	
	[layoutManager setDelegate:self];
	
}
-(void)dealloc
{
	[textContainerLeft release];
	[textStorage release];
	[layoutManager release];
	[super dealloc];
}
- (IBAction)myAction:(id)sender
{

}

//デリゲートメソッド
//完了した
-(void)layoutManager:(NSLayoutManager *)aLayoutManager didCompleteLayoutForTextContainer:(NSTextContainer *)aTextContainer atEnd:(BOOL)flag
{

	NSRange theRange = NSMakeRange(0, [aLayoutManager numberOfGlyphs]);

	[aLayoutManager drawGlyphsForGlyphRange: theRange atPoint: NSMakePoint(10,10)];

	NSLog([NSString stringWithFormat:@"%d",theRange.length]);
}
//無効になった
-(void)layoutManagerDidInvalidateLayout:(NSLayoutManager *)aLayoutManager
{

//NSLog(@"layoutManagerDidInvalidateLayout");
}
@end