我如何自动调整UIScrollView以适应内容 [英] How I auto size a UIScrollView to fit the content

查看:148
本文介绍了我如何自动调整UIScrollView以适应内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让 UIScrollView 自动调整为滚动内容的高度(或宽度)?

Is there a way to make a UIScrollView auto-adjust to the height (or width) of the content it's scrolling?

有些像:

[scrollView setContentSize:(CGSizeMake(320, content.height))];


推荐答案

基于其包含的子视图的 UIScrollView 的内容大小:

The best method I've ever come across to update the content size of a UIScrollView based on its contained subviews:

CGRect contentRect = CGRectZero;
for (UIView *view in self.scrollView.subviews) {
    contentRect = CGRectUnion(contentRect, view.frame);
}
self.scrollView.contentSize = contentRect.size;

这篇关于我如何自动调整UIScrollView以适应内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆