2013-12-23 128 views
1

我已经在uiscrollview上编程添加了多个uitextfields,它的工作正常,并在ios 7中显示文本。但我在iOS 6上不显示文本它只是显示上的UIScrollView这个黑色的背景大的空闲区域面临的问题是代码uitextview文本显示在ios 7上,但不是在ios 6上

// set array values to label 
-(void)addTextViews:(NSArray *)qualArray 
{ 
    //adding qualification label 
    UILabel *qualLbl; 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
    { 
     qualLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, imgVw.bounds.size.height+20, 100, 20)]; 
     [qualLbl setFont:[UIFont boldSystemFontOfSize:14.0]]; 
    } 
    else 
     qualLbl = [[UILabel alloc]initWithFrame:CGRectMake(10, imgVw.bounds.size.height+20, 150, 20)]; 
    [qualLbl setFont:[UIFont boldSystemFontOfSize:20.0]]; 
    } 

    [qualLbl setTextColor:[UIColor colorWithRed:226.0f/255.0f green:73.0f/255.0f blue:20.0f/255.0f alpha:1.0]]; 
    [qualLbl setBackgroundColor:[UIColor clearColor]]; 
    [qualLbl setText:@"Qualification"]; 
    [self.srcVw addSubview:qualLbl]; 
    // adding text views 
    NSLog(@"img view height %f",imgVw.bounds.size.height); 
    height = imgVw.bounds.size.height + 55; 

    for (int i = 0; i < qualArray.count ; i++) { 
     UITextView *txtVw ; 
     UILabel *symbolLabel; 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
     { 
      txtVw =[[UITextView alloc]initWithFrame:CGRectMake(35, height, self.srcVw.bounds.size.width-50, 0)]; 
      [txtVw setFont:[UIFont systemFontOfSize:12.0]]; 

      symbolLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, height, 25, 25)]; 
      [symbolLabel setFont:[UIFont systemFontOfSize:12.0]]; 
     } 
     else 
     { 
      txtVw =[[UITextView alloc]initWithFrame:CGRectMake(35, height, self.srcVw.bounds.size.width-50, 0)]; 
      [txtVw setFont:[UIFont systemFontOfSize:20.0]]; 

      symbolLabel =[[UILabel alloc]initWithFrame:CGRectMake(10, height, 25, 25)]; 
      [symbolLabel setFont:[UIFont systemFontOfSize:12.0]]; 
     } 

     [txtVw setScrollEnabled:NO]; 
     [txtVw setEditable:NO]; 
     [txtVw setText:[NSString stringWithFormat:@"%@" ,[qualArray objectAtIndex:i]]]; 
     [txtVw sizeToFit]; 
     [txtVw setTextColor:[UIColor whiteColor]]; 
     [txtVw setBackgroundColor:[UIColor clearColor]]; 

     [self.srcVw addSubview:txtVw]; 
     // [txtVw setContentMode:UIViewContentModeScaleAspectFit]; 
     //setting symbol label properties 
     [symbolLabel setText:@">"]; 
     [symbolLabel setBackgroundColor:[UIColor clearColor]]; 
     [symbolLabel setTextColor:[UIColor colorWithRed:226.0f/255.0f green:73.0f/255.0f blue:20.0f/255.0f alpha:1.0]]; 
     [self.srcVw addSubview:symbolLabel]; 
     height = height + txtVw.frame.size.height; 
    } 
} 

其代码在IOS 7个工作完美,但我不知道是什么当我在iOS上运行6

+0

我在想,因为你的qualArray可以包含多个元素,为什么你要在每个循环的相同位置添加txtVw和symbolLabel? – ldindu

+0

我怀疑问题似乎是[txtVw setTextColor:[UIColor whiteColor]],默认情况下,textview的背景是白色,而且您使用白色呈现文本。 – ldindu

+0

我已经设置了[txtVw setBackgroundColor:[UIColor clearColor]];并且我还告诉你它在ios 7模拟器上完美的工作 – user3129278

回答

2

您已设置的UITextView的高度,以零(0)

txtVw =[[UITextView alloc]initWithFrame:CGRectMake(35, height, self.srcVw.bounds.size.width-50, 0)]; 

只是将其更改为30

txtVw =[[UITextView alloc]initWithFrame:CGRectMake(35, height, self.srcVw.bounds.size.width-50, 30)]; 
的一点改进

因为在iOS 7中它采用默认大小,但在iOS 6中它没有采用默认值。

0

如果不是您未使用autolayout,最佳做法是更改界面生成器中的变化量。 I added 10 px to the textfield's height

相关问题