UITextField在viewDidLoad方法中调整大小

时间:2014-03-01 03:30:31

标签: ios resize uitextfield viewdidload

我正在开发一个具有一系列用于数据输入的UItextFields的应用程序,我希望它们根据设备类型动态地在屏幕上留出空间,并且它运行良好,但是UITextFields已经缩小,我不能让它们保持原来的宽度。文本字段已添加到故事板中的视图中,并且为130x31。 在底部添加子视图for循环后,它们大约是31像素宽。

 - (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    // for debugging
    NSLog(@"opsToolsSevenHundred view did load");

    // Spaces the text fields labels and buttons in the view
    int i =0;

    NSArray *viewSubViews = [self.view subviews];
    for (i=0; i<[viewSubViews count]; i++) {
        [[viewSubViews objectAtIndex:i] removeFromSuperview];
    };



    float numberOfFields = 10;
    float alignmentCount = numberOfFields+1;
    float textFieldCenter = (self.view.frame.size.width/4)*3;
    float topFourLabelCenter = ((self.view.frame.size.width/7)*3);
    float bottomSixLabelCenter = ((self.view.frame.size.width/3));
    float buttonCenter = (self.view.frame.size.width/6);
    float navBarHeight = self.navigationController.navigationBar.frame.size.height;
    float verticleSpacingOffset = (self.view.frame.size.height - navBarHeight)/alignmentCount;
    self.oneTextField.center = CGPointMake (textFieldCenter, (verticleSpacingOffset + navBarHeight
    self.twoTextField.center = CGPointMake(textFieldCenter, (verticleSpacingOffset*2) + navBarHeight);
    self.threeTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*3)+navBarHeight));
    self.fourTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*4) + navBarHeight));
    self.fiveTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*5) + navBarHeight));
    self.sixTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*6) + navBarHeight));
    self.sevenTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*7) + navBarHeight));
    self.eightTextField.center   = CGPointMake(textFieldCenter, ((verticleSpacingOffset*8) + navBarHeight));
    self.nineTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*9) + navBarHeight));
    self.tenTextField.center = CGPointMake(textFieldCenter, ((verticleSpacingOffset*10) + navBarHeight));
    self.oneLabel.center  = CGPointMake(topFourLabelCenter, ((verticleSpacingOffset) + navBarHeight));
    self.twoCountLabel.center  = CGPointMake(topFourLabelCenter, ((verticleSpacingOffset*2) + navBarHeight));
    self.threeLoadLabel.center = CGPointMake(topFourLabelCenter, ((verticleSpacingOffset*3) + navBarHeight));
    self.fourLabel.center = CGPointMake(topFourLabelCenter, ((verticleSpacingOffset*4) + navBarHeight));
    self.fiveLabel.center = CGPointMake(bottomSixLabelCenter, ((verticleSpacingOffset*5) + navBarHeight));
    self.sixLabel.center = CGPointMake(bottomSixLabelCenter, ((verticleSpacingOffset*6) + navBarHeight));
    self.sevenLabel.center = CGPointMake(bottomSixLabelCenter, ((verticleSpacingOffset*7) + navBarHeight));
    self.eightLabel.center = CGPointMake(bottomSixLabelCenter, ((verticleSpacingOffset*8) + navBarHeight));
    self.nineLabel.center = CGPointMake(bottomSixLabelCenter, ((verticleSpacingOffset*9) + navBarHeight));
    self.tenLabel.center = CGPointMake(bottomSixLabelCenter, ((verticleSpacingOffset*10) + navBarHeight));
    self.oneButton.center = CGPointMake(buttonCenter, ((verticleSpacingOffset*1.5)+navBarHeight));
    self.twoButton.center = CGPointMake(buttonCenter, ((verticleSpacingOffset*2.5)+navBarHeight));
    self.threeButton.center = CGPointMake(buttonCenter, ((verticleSpacingOffset*3.5)+navBarHeight));

    i=0;

    for (i=0; i<[viewSubViews count]; i++) {
        [self.view addSubview:[viewSubViews objectAtIndex:i]];
    }
} 

0 个答案:

没有答案