1

i have added multiple uitextfields programatically on uiscrollview its working fine and displaying text in ios 7 . but i am facing problem on ios 6 it does not display text its just display a large empty area with black background on uiscrollview this is the code

// 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;
    }
}

its code working perfect in ios 7 but i don't know what is problen when i run it on ios 6

3
  • I am wondering, since your qualArray can contains more than one elements, why are you adding txtVw and symbolLabel at same position on every loop? Commented Dec 23, 2013 at 11:03
  • I suspect problem appeared to be [txtVw setTextColor:[UIColor whiteColor]] as by default textview's background is white and you are rendering text with white color. Commented Dec 23, 2013 at 11:05
  • i have set [txtVw setBackgroundColor:[UIColor clearColor]]; and also i told you its working perfectly on ios 7 simulator Commented Dec 23, 2013 at 11:09

2 Answers 2

2

you have set height of uitextview to Zero(0)

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

just change it to 30

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

because in iOS 7 it takes default size but in iOS 6 it not taking default value.

Sign up to request clarification or add additional context in comments.

Comments

0

The best practice is to change the deltas in the interface builder if not you are not using autolayout.I added 10 px to the textfield's height

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.