I'm trying to get a UILabel to scroll inside of a UIScrollView but it doesnt scroll

人走茶凉 提交于 2019-12-05 08:49:04
Dawson Toth

A really simple answer, if you just want a single scrollable label, would be to use UITextView instead (reference). Disable editing, and you get a scrollable label.

(Taken almost verbatim from: how to add a scroll function to a UILabel)

Jerry Jones

UIScrollView won't scroll if it's contents are not larger than it's visible area. Considering you are assigning the text to the label after you've set contentSize of the scrollview, it is unlikely that this is happening correctly. I would try something like this...

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.scrollView addSubview:summaryLabel];

    .....

    summaryLabel.text = str;

    // Assuming your label has numberOfLines = 0, and you want to scroll vertical
    CGSize maxSize = CGSizeMake(summaryLabel.frame.size.width, CGFLOAT_MAX);
    CGSize labelSize = [summaryLabel sizeThatFits:maxSize];
    scrollview.contentSize = labelSize;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!