2013-05-11 63 views
0

我需要包含(标题,图像和详细信息)的视图,详细信息是关于textview的。在可滚动对象中组合uitextview,uilabel和uiimageview ios

我需要的是,允许滚动到所有视图,而不仅仅是texview。 在我的应用程序,如果我禁用滚动,TextView是被切断,因为身高不是动态:

enter image description here

在我的代码

,我把这样的:

CGRect frame = self.detailTextView.frame; 
    frame.size.height = self.detailTextView.contentSize.height; 
    self.detailTextView.frame = frame; 
    [self.detailTextView sizeToFit]; 
    self.detailTextView.text = [[fastResults objectAtIndex:0] objectForKey:@"content"]; 

这fastResults是一个包含数据的字典。

我需要像例如BBC应用的视图:

enter image description here

SO,我需要让TextView的高度是动态的并且让所有的视图是可滚动在一起。 注意:所有这些元素都处于滚动视图中。

这是我的界面生成器:

enter image description here

谢谢你的帮助;

回答

0

首先,您必须在调整文本大小之前在文本视图上设置文本。所以,你应该有类似:

self.detailTextView.text = [[fastResults objectAtIndex:0] objectForKey:@"content"]; 
    CGRect frame = self.detailTextView.frame; 
    frame.size.height = self.detailTextView.contentSize.height; 
    self.detailTextView.frame = frame; 
// [self.detailTextView sizeToFit]; you don't need this anymore 

//after you resized the self.details.textView you have to change the scrollview content size 

yourScrollView.contentSize = CGSizeMake(yourScrollView.contentSize.width, 
             yourImageHeight + yourTitleHeight + self.detailsTextView.frame.size.height); 
+0

还是文字被切断了,我应该在故事板检查器中编辑一些东西吗? – CarinaM 2013-05-11 10:04:16

+0

你在使用autoLayout吗? – danypata 2013-05-11 10:08:22

+0

我已经附加了我的界面生成器的截图,在视图检查器元素框架矩形被选中,你是什么意思的自动布局? – CarinaM 2013-05-11 10:13:51

0

你可以先在你的TextView中(see this)是把NSString的高度,然后设置的TextView作为字符串的计算高度的高度。
也许,如果textview的高度大于scrollview contentSize的高度,则还需要将scrollview的contentSize的高度调整为textview框架的高度。然后禁用textview上的滚动。