我已經在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
我在想,因爲你的qualArray可以包含多個元素,爲什麼你要在每個循環的相同位置添加txtVw和symbolLabel? – ldindu
我懷疑問題似乎是[txtVw setTextColor:[UIColor whiteColor]],默認情況下,textview的背景是白色,而且您使用白色呈現文本。 – ldindu
我已經設置了[txtVw setBackgroundColor:[UIColor clearColor]];並且我還告訴你它在ios 7模擬器上完美的工作 – user3129278