【发布时间】:2011-02-21 14:02:56
【问题描述】:
可能重复:
How can i fix my scrollView dynamically when i have more than one textViews in it?
我在界面生成器中创建了一个滚动视图,并在其中放置了 3 个文本视图和 2 个按钮。有时 textViews 有更多的文本,有时更少。我设法给他们灵活的框架尺寸。但如果顶部 textView 有更多文本,那么它的一些文本会超过第二个 textView。我试过这段代码。我认为它应该工作,但它不能正常工作。
storyTitle.text = sTitle;
storyTitle.font = [UIFont boldSystemFontOfSize:18];
date.text = sDate;
date.font = [UIFont systemFontOfSize:16];
summary.text = sSummary;
summary.font = [UIFont systemFontOfSize:16];
CGRect titleFrame = storyTitle.frame;
titleFrame.size.height = storyTitle.contentSize.height;
storyTitle.frame = titleFrame;
CGRect dateFrame = date.frame;
dateFrame.size.height = label.contentSize.height;
date.frame = dateFrame;
CGRect summaryFrame = summary.frame;
summaryFrame.size.height = summary.contentSize.height;
summary.frame = summaryFrame;
CGRect topTextViewFrame = storyTitle.frame;
CGRect middleTextViewFrame = date.frame;
NSLog(@"size: %d",topTextViewFrame.origin.y);
middleTextViewFrame.origin.y = topTextViewFrame.origin.y + topTextViewFrame.size.height;
CGRect bottomTextViewFrame = summary.frame;
bottomTextViewFrame.origin.y = middleTextViewFrame.origin.y + middleTextViewFrame.size.height;
// then adjust other controls based on these frames, for example:
CGRect myButtonFrame = detailButton.frame;
myButtonFrame.origin.y = bottomTextViewFrame.origin.y + bottomTextViewFrame.size.height;
CGRect myButtonFrame2 = fbButton.frame;
myButtonFrame2.origin.y = myButtonFrame.origin.y + myButtonFrame.size.height;
// finally adjust the contentSize of the scrollview assuming the button is the bottom element
CGSize csize = scrollView.contentSize;
csize.height = myButtonFrame2.origin.y + myButtonFrame2.size.height;
scrollView.contentSize = csize;
谁能告诉我这有什么问题?以及我应该如何纠正它才能正常工作。提前谢谢
【问题讨论】:
-
请编辑原始问题以添加新的详细信息,而不是针对完全相同的问题打开新问题。
标签: iphone objective-c cocoa-touch interface-builder ios-4.2