自动调整大小从XIB发出一些,一些使用编程方式

时间:2014-10-29 06:54:31

标签: ios objective-c xcode6 autoresize

我使用XIB(自动调整大小)和Xcode 6开发了屏幕。在这个UI中是动态的,因此以编程方式将UI添加到屏幕。用户界面在3.5英寸和4英寸模拟器中看起来很不错

动态添加UI的代码是

-(void)addContenttoScrollview{

    ypostion=190;
    CGRect lframe = [UIScreen mainScreen].bounds;

    for (int i=0; i<[[[CalculateDataGetter sharedInstance]ChemicalListArray] count]; i++) {
        UIView *contentview = [[UIView alloc] initWithFrame:CGRectMake(10, ypostion, lframe.size.width-35, 24)];
       [self.calculateScrollView addSubview:contentview];
        contentview.backgroundColor = [UIColor colorWithRed:255.0 green:255.0 blue:255.0 alpha:0.4];
        contentview.layer.borderColor = AgroClinic_Border_COLOR.CGColor;
        contentview.layer.borderWidth =1.5;
        contentview.tag=111;
        ypostion=ypostion+24+10;

        UILabel *chemicalFormulaLbl = [[UILabel alloc] init];
        chemicalFormulaLbl.font = FONT_HELVETICANEUE(14);
        chemicalFormulaLbl.lineBreakMode = NSLineBreakByWordWrapping;
        chemicalFormulaLbl.numberOfLines=0;
        chemicalFormulaLbl.textColor = AgroClinic_Border_COLOR;
        chemicalFormulaLbl.backgroundColor=CLEAR_COLOR;
        chemicalFormulaLbl.frame= CGRectMake(10, 2, 120, 20);
        chemicalFormulaLbl.text = [[[[CalculateDataGetter sharedInstance]ChemicalListArray] objectAtIndex:i] valueForKey:@"FORMULA"];
        [contentview addSubview:chemicalFormulaLbl];
        chemicalFormulaLbl=nil;

        UILabel *valueLabel = [[UILabel alloc] init];
        valueLabel.font = FONT_HELVETICANEUE(14);
        valueLabel.lineBreakMode = NSLineBreakByWordWrapping;
        valueLabel.numberOfLines=0;
        valueLabel.textColor = AgroClinic_Border_COLOR;
        valueLabel.backgroundColor=CLEAR_COLOR;
        valueLabel.frame= CGRectMake(200, 2, 120, 20);
        valueLabel.text = [[[[CalculateDataGetter sharedInstance]ChemicalListArray] objectAtIndex:i] valueForKey:@"PESTQUANTITY"];
        valueLabel.tag=i;
        [contentview addSubview:valueLabel];
        valueLabel=nil;
    }
    [self.calculateScrollView setContentSize:CGSizeMake(lframe.size.width,ypostion+40)];
}

enter image description here enter image description here

先谢谢

1 个答案:

答案 0 :(得分:0)

尝试此操作从XIB视图高度计算UI,并将Y位置设置为以下动态视图。

相关问题