How to add a scroll function to a UILabel How to add a scroll function to a UILabel xcode xcode

How to add a scroll function to a UILabel


Use UITextView (reference).

It's designed to do exactly that. Disable editing, and you get a scrollable label.


You can add your UILabel on a UIScrollView Like this and can also do like this---

scrollView.backgroundColor = [UIColor clearColor];        UILabel * label = [[UILabel alloc] init];        [label setNumberOfLines:0];        label.text=[detailDict valueForKey:@"ABC"];        [label setFont:[UIFont fontWithName:@"Georgia" size:16.0]];        CGSize labelsize=[label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(250, 1000.0) lineBreakMode:UILineBreakModeWordWrap];        int y=0;        label.frame=CGRectMake(38, y, 245, labelsize.height);        [label setBackgroundColor:[UIColor clearColor]];        [label setTextColor:[UIColor whiteColor]];        scrollView.showsVerticalScrollIndicator = NO;        y+=labelsize.height;        [scrollView setContentSize:CGSizeMake(200,y+50)];        [scrollView addSubview:label];        [label release];

Here Y is used to increase or decrease the label size as the text.