Dynamically insert more 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态插入更多 UITextFields
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01