可可:如何制作多行NSTextField? [英] Cocoa : How to make multiline NSTextField?

查看:335
本文介绍了可可:如何制作多行NSTextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何制作多行NSTextField? 更新:我在IB中发现了一种特殊的NSTextField类型,称为包装的文本字段".它是多行,但是当我想换行时,我必须按Ctrl + Enter.但我只想按Enter换行.我该怎么办?

How to make multiline NSTextField? UPDATE: I've found in IB special type of NSTextField called "Wrapped Text Field". It is multiline but when I want get a newline I have to press Ctrl+Enter. But I want to press only Enter to get a newline. How can I do it?

推荐答案

无法仅在Interface Builder中指定此行为.您可以按照此技术说明 QA1454中所述的委托消息来完成此操作. .

There is no way to specify this behavior solely in Interface Builder. You can do it with a delegate message as described in this tech note QA1454.

这是技术说明中的示例委托消息:

Here is the example delegate message from the tech note:

- (BOOL)control:(NSControl*)control textView:(NSTextView*)textView doCommandBySelector:(SEL)commandSelector
{
    BOOL result = NO;

    if (commandSelector == @selector(insertNewline:))
    {
        // new line action:
        // always insert a line-break character and don’t cause the receiver to end editing
        [textView insertNewlineIgnoringFieldEditor:self];
        result = YES;
    }
    else if (commandSelector == @selector(insertTab:))
    {
        // tab action:
        // always insert a tab character and don’t cause the receiver to end editing
        [textView insertTabIgnoringFieldEditor:self];
        result = YES;
    }

    return result;
}

这篇关于可可:如何制作多行NSTextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆