如何在不同的框架上制作 UITextField? [英] how to make the UITextField on different frame?

查看:29
本文介绍了如何在不同的框架上制作 UITextField?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要创建的 UITextField 数组.但 UITextField 保持在同一个框架上?这是我的代码.当您按下按钮时,它会创建一个新的 UITextField.

i have an array for my UITextField to be created. but the UITextField remain on the same Frame?Here is my code. It create a new UITextField when you press the button.

-(IBAction)textFieldcreating{


    textfieldform = [[NSMutableArray alloc] init];
    textField1 = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 100, 40)];
    textField1.borderStyle = UITextBorderStyleRoundedRect;
    textField1.font = [UIFont systemFontOfSize:15];
    textField1.placeholder = @"enter text";
    textField1.autocorrectionType = UITextAutocorrectionTypeNo;
    textField1.keyboardType = UIKeyboardTypeDefault;
    textField1.returnKeyType = UIReturnKeyDone;
    textField1.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
    textField1.delegate = self;

    [textfieldform addObject:textField1];

    int counter;
    counter = 0;
    if(counter < [textfieldform count])
    {


            textField1.frame = CGRectMake(textField1.frame.origin.x+30, textField1.frame.origin.x+40, textField1.frame.size.width+40, textField1.frame.size.height+50);
            [self.view addSubview:textField1];

        counter++;
    }

}

推荐答案

你正在做的是创建一个新的 Array 并保持所有 UITextViews 的 xOrigin 和 yOrigin 相同!

What you are doing is creating a new Array and keeping the xOrigin and yOrigin same for all the UITextViews!

做这样的事情.

在.h文件中,声明

@property (nonatomic, retain) NSMutableArray *textfieldform;
@property (nonatomic, readwrite) int yOrigin;

在.m文件中,在viewDidLoad函数中,

in .m file, in viewDidLoad function,

self.textfieldform = [NSMutableArray arrayWithCapacity:0];
yOrigin = 0;

现在,您的函数看起来像这样.

now, your function looks like this.

-(IBAction)textFieldcreating{


    //textfieldform = [[NSMutableArray alloc] init]; NO NEED OF THIS LINE NOW
    textField1 = [[UITextField alloc] initWithFrame:CGRectMake(10, yOrigin, 100, 40)];
    textField1.borderStyle = UITextBorderStyleRoundedRect;
    textField1.font = [UIFont systemFontOfSize:15];
    textField1.placeholder = @"enter text";
    textField1.autocorrectionType = UITextAutocorrectionTypeNo;
    textField1.keyboardType = UIKeyboardTypeDefault;
    textField1.returnKeyType = UIReturnKeyDone;
    textField1.clearButtonMode = UITextFieldViewModeWhileEditing;
    textField1.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;    
    textField1.delegate = self;

    [textfieldform addObject:textField1];

    yOrigin = yOrigin + 40 + 10; //old yorigin + btn height + y offset
}

如果你也想改变 xOrigin,那么用 xOrigin 取另一个变量

If you want changes in xOrigin too, then take another variable with xOrigin

这篇关于如何在不同的框架上制作 UITextField?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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