2014-10-29 26 views
0

我已經開發了使用XIB(自動調整大小)和Xcode 6的屏幕。在這一些UI是動態的,因此以編程方式將UI添加到屏幕。用戶界面是在3.5和4英寸模擬器自動調整一些來自XIB和一些使用編程方式

的動態添加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

感謝好看提前

回答

0

試試這個計算從XIB的UI查看高度並將Y位置設置爲下面的動態視圖。

+0

但是當超視圖內容增加時,應該增加編程式添加的UI的高度 – 2014-10-29 07:01:27

相關問題