How to add a scroll function to a UILabel

前端 未结 2 1798
耶瑟儿~
耶瑟儿~ 2020-12-14 06:15

In Xcode, I created a UILabel which will autoresize depending on how many lines of text I put on it. But I don\'t want the UILabel\'s height to exceed a certain limit (240 i

2条回答
  •  無奈伤痛
    2020-12-14 06:36

    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.

提交回复
热议问题