glyphIndexForPoint:inTextContainer:fractionOfDistanceThroughGlyph:
テキストコンテナの範囲で指定した位置にもっとも近い文字の番号を返す
-(unsigned int)glyphIndexForPoint:(NSPoint)aPoint: inTextContainer:(NSTextContainer *)aTextContainer: fractionOfDistanceThroughGlyph:(float *)partialFraction:
解説
テキストコンテナの範囲で指定した位置にもっとも近い文字の番号を返す。
aPointはテキストコンテナでの座標。
たとえば、テキストビュ−でマウスクリックした時にどの文字を選択するかの判定などに使われます。
返り値
( unsigned int )
整数値
引数
( NSPoint )aPoint
位置
( NSTextContainer * )aTextContainer
テキストコンテナ
( float * )partialFraction
フレームワーク
ApplicationKit
クラス
NSLayoutManager
Instance Methods
使用可能
10.0
参照
例文
#import "MyObject.h" @implementation MyObject - (IBAction)myAction:(id)sender { //myOutletはTextView NSLayoutManager *layoutManager = [myOutlet layoutManager]; NSTextContainer *textContainer = [myOutlet textContainer]; float fraction; unsigned int glyphIndex; [myOutlet insertText:@"abcdefghil"]; glyphIndex = [layoutManager glyphIndexForPoint:NSMakePoint(30,5) inTextContainer:textContainer fractionOfDistanceThroughGlyph:&fraction]; NSLog([NSString stringWithFormat:@"index = %u,fraction = %f",glyphIndex,fraction]); } @end