0

I have a view which has details of some event,which includes imageview, some labels etc. I have the description of the event as a small subview in the view which is scrollable as below.

CGRect descriptionTextViewRect = CGRectMake(15, 185, 280, 85);
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect];
descriptionText.textAlignment = UITextAlignmentLeft;
descriptionText.text =des;
descriptionText.editable = NO;
descriptionText.layer.cornerRadius = 5.0;
descriptionText.clipsToBounds = YES;
descriptionText.userInteractionEnabled = YES;
descriptionText.font = [UIFont systemFontOfSize:15];
[scrollView addSubview: descriptionText];

I followed this link but I get scrollable for both text view as well as the scrollview

I followed like this

float sizeOfContent = 0;
 int i ;

for (i=0; i<[scrollView.subviews count]; i++) {
    sizeOfContent += descriptionText.frame.size.height;
}

scrollView.contentSize = CGSizeMake(descriptionText.frame.size.width, sizeOfContent)

I need to display the whole content of the description and make the whole detail page scrollable.

Am I doing it correctly? Or am I missing out somthing?

How do I do that?

Thank you.

Community
  • 1
  • 1
user1268938
  • 55
  • 1
  • 1
  • 9

2 Answers2

0

You are adding the same item's height for several times.

This:

for (i=0; i<[scrollView.subviews count]; i++) {
    sizeOfContent += descriptionText.frame.size.height;
}

Should be this:

for (UIView *view in scrollView.subviews) {
    sizeOfContent += view.frame.size.height;
}

So it will correctly add all item's heights to sizeOfContent.

basar
  • 983
  • 9
  • 16
  • exactly , but i need to set the size of the description text and make the detail page scrollable. I am now able to scroll only the description text. Can you advice on this please? – user1268938 Jul 01 '12 at 13:09
0

You are adding subView at same position every time. For example: if you are adding 5 subViews it should be like as followings:

for(int i=0; i<5; i++)
{
CGRect descriptionTextViewRect = CGRectMake(15, i*185, 280, 85);
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect];
descriptionText.textAlignment = UITextAlignmentLeft;
descriptionText.text =des;
descriptionText.editable = NO;
descriptionText.layer.cornerRadius = 5.0;
descriptionText.clipsToBounds = YES;
descriptionText.userInteractionEnabled = YES;
descriptionText.font = [UIFont systemFontOfSize:15];
[scrollView addSubview: descriptionText];
}
Abdullah Md. Zubair
  • 3,312
  • 2
  • 30
  • 39