如何在iOS应用中添加文本区域

时间:2013-01-06 14:26:53

标签: iphone ios6 uitextfield uitextview

我是iPhone应用程序的新手。我想添加TextArea。我知道如何添加textField,但有人可以帮助我如何在我的iPhone应用程序中使用Textare?

我想,我可以增加文本字段的高度并使其成为多行,但是那个选项不存在。

3 个答案:

答案 0 :(得分:8)

您无法增加UITextField的高度。为此,您需要使用UITextView。 在您有“UITextField”的“界面”构建器中,还有一个UITextView选项。 您可以在iPhone中使用与UITextField相同的UITextView。 UITextView用于多行

UITextView  *txt = [[UITextView  alloc]init];

//set frame

//add on view

[self.view addSubView:txt];

[txt release];

我希望这可以解决您的问题Sample Code for TextView

答案 1 :(得分:3)

UITextView  *txt = [[UITextView  alloc]initwithframe:CGRectMake(x, y, width,height)];



[self.view addSubView:txt];

[txt release];

答案 2 :(得分:0)

您可以通过点击Mainstoryboard.storyboardviewController.xib然后拖动UITextView来执行此操作。这将允许多行文字。如果需要访问Textview,请键入:

.h file

{
  IBOutlet UIITextView *textView;
}

 @property (nonatomic, strong) IBOutlet UITextView* textView;

.m file
@synthesize textView;

修改

获取用户数据,连接故事板中的插座,

然后使用:

-(void)getUserText{
NSLog@"%@", self.textView);


}

这应该打印出用户在textView中输入的内容。