【问题标题】:NSTextField - how to change size and position of text/editing area?NSTextField - 如何更改文本/编辑区域的大小和位置?
【发布时间】:2012-11-18 12:39:32
【问题描述】:

嗯,我知道了:http://d.pr/i/jItM

我显然想将文本从左边缘向下移动。我有 NSTextField 的子类,我在其中绘制背景,但我无法找到这个。

【问题讨论】:

  • 所以我已经设法在不编辑时根据需要定位文本。但是,当我开始编辑文本时,它会移回左上角!我不知道如何定位 fieldEditor,我尝试覆盖 NSTextFieldCell 中的各种方法。

标签: objective-c macos cocoa appkit


【解决方案1】:

知道了。两者都需要被覆盖。

- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
    aRect.origin.y += 9;
    aRect.origin.x += 10;
    [super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
}

- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(NSInteger)selStart length:(NSInteger)selLength
{
    aRect.origin.y += 9;
    aRect.origin.x += 10;
    [super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-06
    • 2019-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多