【问题标题】:Adding a UITextview as a toolbar item将 UITextview 添加为工具栏项
【发布时间】:2011-06-27 05:32:40
【问题描述】:

我正在为 iPhone 创建一个消息传递应用程序。 我希望用户能够在按下回车键时输入换行符。 但是我无法将 UITextview 放在工具栏项中。 我在 UITextView 上也看到了同样的情况。 当按下返回键时,我想在 UITextField 中获取新行。这可能吗?

请帮忙 提前致谢。

【问题讨论】:

  • 您遇到了什么麻烦?请具体。

标签: iphone objective-c uitextfield uitextview


【解决方案1】:

您无法使用 IB 添加它,但您可以通过编程方式添加它。您需要设置它的contentInset,以便文本内容在编辑时不会被向上推,因为文本视图的大小受限,内容将变得不可见。我在下面的示例代码中添加了这一点。

示例代码

UITextView * textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 32)] autorelease];
textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
UIBarButtonItem * barItem = [[[UIBarButtonItem alloc] initWithCustomView:textView] autorelease];

self.toolbar.items = [NSArray arrayWithObject:barItem];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多