Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UIScrollview height dynamically using programming

I've used UIScrollview in my iPhone app. I've set default size of UIScrollview 320 * 548. I want to increase UIScrollview height dynamically using programming but i am not succeed yet. I've used below code

 CGRect scrollFrame;

scrollFrame.origin = _tblScroolView.frame.origin;

scrollFrame.size = CGSizeMake(320, 700);

_tblScroolView.frame = scrollFrame; 

Please help me

Thanks!

like image 762
Shailesh Avatar asked Jun 17 '13 09:06

Shailesh


3 Answers

To change the size of scroll view

scrollView.frame = CGRectMake(originX, originY, width, height);

to change the size of scrollable area:

scrollView.contentSize = CGSizeMake(width, height);

Swift 3 version

scrollView.frame = CGRect(x: scrollX, y: scrollY, width:width, height:height)

scrollView.contentSize = CGSize(width:width, height: height)
like image 133
Mert Avatar answered Oct 23 '22 16:10

Mert


trigger any function when you need to increase your scrollview then use this code in that function and make your desired size for scrollview

scrollViewName.frame = CGRectMake(originX, originY, width, height);

change scrollable area

scrollViewName.content.size = CGSizeMake(width, height);...
like image 2
Kuriakose Pious P Avatar answered Oct 23 '22 16:10

Kuriakose Pious P


int height = 600;
for (i = 0; i<5; i++)
{
  // do what you want. suppose you create a view which size is - 10,10,300,800.

  height = createdView.frame.size.height+10;
}

scrollView.contentSize = (320, height);

Hope this will help you.

like image 1
Sudhir Kumar Avatar answered Oct 23 '22 17:10

Sudhir Kumar