动态插入更多 UITextFields

Dynamically insert more UITextFields(动态插入更多 UITextFields)
本文介绍了动态插入更多 UITextFields的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个附加屏幕截图中描述的要求.单击蓝色添加按钮时,必须在最后一个文本字段和 textview 之间插入一个 UItextfield,并且必须在动态插入的新 uitextfield 旁边出现蓝色添加按钮.任何人都可以建议如何实现这一目标.我已将所有字段放在 UIScrollview 中.

I have a requirement as described in the attached screen shot. When blue add button is clicked, one more UItextfield have to be inserted between last text field and textview and Blue add button will have to appear beside that dynamically inserted new uitextfield. Could any one suggest how to achieve this. I have placed all the fields in UIScrollview.

滚动视图未启用:

推荐答案

你可以这样做:

在 .h 中,我有一个名为 previousTextField 的插座,它连接到第一个插座.顾名思义,它将存储最新添加的文本字段.

In .h I have an outlet called previousTextField which is hooked to the first one. As name suggests it will store the latest added textField.

在这里找到正在运行的项目.

Find running project here.

-(IBAction)addTextField:(id)sender{
    float x=previousTextField.frame.origin.x;
    float y=previousTextField.frame.origin.y+50;//get y from previous textField and add 10 or so in it.
    float w=previousTextField.frame.size.width;
    float h=previousTextField.frame.size.height;
    CGRect frame=CGRectMake(x,y,w,h);
    UITextField *textField=[[UITextField alloc] initWithFrame:frame];
    textField.placeholder = @"Enter User Name or Email";


    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15];
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;


    [self.view addSubview:textField];
    previousTextField=textField;
}

只是一个想法/算法如何去,而不是编译器检查

我错过了,改变 + 按钮的位置.我认为你可以做到:)

I missed on thing, changing the location of + button. I think you can do it :)

在上述方法中添加以下内容

//move addbutton which is an outlet to the button
CGRect frameButton=CGRectMake(addButton.frame.origin.x, addButton.frame.origin.y+50, addButton.frame.size.width, addButton.frame.size.height);
[addButton removeFromSuperview];
[addButton setFrame:frameButton];
[self.view addSubview:addButton];

这篇关于动态插入更多 UITextFields的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
Resume game cocos2d(恢复游戏 cocos2d)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)