How to scroll UIlabel Text and set it width and Hight dynamically in objective c
<p>I am new in iOS and I am facing a problem to scroll the label text.My code is able to scroll the label text but it width is not setting properly. code is like this</p>

<pre><code> NSString * htmlString = @"&lt;html&gt;&lt;body&gt;";
    NSString *htmlString2=@"&lt;/body&gt;&lt;/html&gt;";
    NewString=[NSString stringWithFormat:@"%@%@%@",htmlString,result,htmlString2];

    NSLog(@"New String =%@",NewString);

    NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[NewString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];



    NSLog(@"String Value = %@",result);
   // [myDataNSMArray addObject:idarray];

    shortnamearray=[[NSMutableArray alloc]init];
    shortnamearray=[responsedict valueForKey:@"abc"];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,700, 1800)];
        NSString *theText = @"A long string";
        CGRect labelRect = CGRectMake(10, 50, 300, 50);
        lbl.adjustsFontSizeToFitWidth = YES;
        [lbl setNumberOfLines:0];
        CGFloat fontSize = 30;
        while (fontSize &gt; 0.0)
        {
            CGSize size = [theText sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];

            if (size.height &lt;= labelRect.size.height) break;

            fontSize -= 1.0;
        }

        //set font size
        lbl.font = [UIFont fontWithName:@"Arial" size:fontSize];
    }
    else
    {
        lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,350, 800)];
    }
    NSLog(@"Result Array =%@",shortnamearray);
    CGFloat y = 10;

    NSMutableArray* animals = [NSMutableArray new];

    NSUInteger maxCount = headarray.count &gt; shortnamearray.count ? headarray.count : shortnamearray.count;
    for (int i = 0; i &lt; maxCount; i ++) {
        if ([headarray objectAtIndex:i]) {
            [animals addObject:[headarray objectAtIndex:i]];
        }
        if ([shortnamearray objectAtIndex:i]) {
            [animals addObject:[shortnamearray objectAtIndex:i]];
        }
    }
    NSLog(@"Array is =%@",animals);

    for(int i=0;i&lt;[shortnamearray count] &amp;&amp; i&lt;[headarray count];i++){
        // y+=20;
        y+=10;

        NSString *newArray =[animals objectAtIndex:i];
        newArray=[animals componentsJoinedByString:@""];

        NSString *NewString;

        [lbl setLineBreakMode:NSLineBreakByWordWrapping];
         lbl.textAlignment = NSTextAlignmentCenter;
        NSString * htmlString = @"&lt;html&gt;&lt;body&gt;";
        NSString *htmlString2=@"&lt;/body&gt;&lt;/html&gt;";
        NewString=[NSString stringWithFormat:@"%@%@%@",htmlString,newArray,htmlString2];

        NSLog(@"New String =%@",NewString);

        NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[NewString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

        lbl.attributedText = attrStr;


        NSString *theText = @"A long string";
        CGRect labelRect = CGRectMake(10, 50, 300, 50);
        lbl.adjustsFontSizeToFitWidth = YES;
        [lbl setNumberOfLines:0];
        CGFloat fontSize = 15;
        while (fontSize &gt; 0.0)
        {
            CGSize size = [theText sizeWithFont:[UIFont fontWithName:@"Verdana" size:fontSize] constrainedToSize:CGSizeMake(labelRect.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping];

            if (size.height &lt;= labelRect.size.height) break;

            fontSize -= 1.0;
        }

        //set font size
        lbl.font = [UIFont fontWithName:@"Arial" size:fontSize];
    }

    NSTimer *timer = [NSTimer timerWithTimeInterval:1
                                             target:self
                                           selector:@selector(timer)
                                           userInfo:nil
                                            repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

    //[_scrollView scrollRectToVisible:NSMakeRange(0,0,0.0) animated:YES];
    [scroll addSubview:lbl];
    [UIView commitAnimations];

    scroll.contentSize=CGSizeMake(scroll.frame.size.width+[shortnamearray count], lbl.frame.size.height);
</code></pre>

<p>I am using like this code but it width is not set dynamically. How to set width in this dynamically. Thanks in Advance!</p>