Calculate the contentsize of scrollview(计算scrollview的contentsize)
问题描述
我有一个滚动视图作为表格视图单元格的详细视图.我正在通过界面生成器创建的详细视图上有多个视图,例如标签、按钮等.我通过界面生成器创建的是静态的.我把所有东西都放在高度 480 的视图上.
I'm having a scrollview as the detailedview of tableview cell. There are multiple views on the detailedview like labels, buttons etc. which I'm creating through interface builder. What I'm creating through interface builder is static. I'm putting everything on a view of height 480.
我的详细视图上的标签具有可以扩展到任意长度的动态文本.问题是我需要设置滚动视图的内容大小,我需要它的高度.
A label on my detailedview is having dynamic text which can extend to any length. The problem is that I need to set the scrollview's content size for which I need its height.
如果内容是动态的,我应该如何设置滚动视图的高度?
How shall I set scrollview's height provided the content is dynamic?
推荐答案
你可以尝试使用scrollview'ers ContentSize.它对我有用,我在使用动态内容的控件时遇到了同样的问题.
You could try to use the scrollview'ers ContentSize. It worked for me and I had the same problem with the control using dynamic content.
// Calculate scroll view size
float sizeOfContent = 0;
int i;
for (i = 0; i < [myScrollView.subviews count]; i++) {
UIView *view =[myScrollView.subviews objectAtIndex:i];
sizeOfContent += view.frame.size.height;
}
// Set content size for scroll view
myScrollView.contentSize = CGSizeMake(myScrollView.frame.size.width, sizeOfContent);
我在控制器中名为 viewWillAppear 的方法中为包含滚动视图的视图执行此操作.这是我在调用 super 上的 viewDidLoad 之前做的最后一件事.
I do this in the method called viewWillAppear in the controller for the view that holds the scrollview. It is the last thing i do before calling the viewDidLoad on the super.
希望它能解决你的问题.
Hope it will solve your problem.
//汉内斯
这篇关于计算scrollview的contentsize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:计算scrollview的contentsize
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01