How to set content size of UIScrollView dynamically
iphone, objective-c, uiscrollview, uiview
Solution
One more easy way
- (void)viewDidLoad
{
float sizeOfContent = 0;
UIView *lLast = [scrollView.subviews lastObject];
NSInteger wd = lLast.frame.origin.y;
NSInteger ht = lLast.frame.size.height;
sizeOfContent = wd+ht;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
}
Problem
I got question about `UIScrollview`. The story is I have a `UIView` named ChartsView which I re-draw it myself by override method `drawRect()`. The content of drawing was generated dynamically. So I do not know its size until runtime. The question is how/where can I set its super view's (scrollView) content size dynamically?Any idea about that? ``` - (void)viewDidLoad { [super viewDidLoad]; // not this way. it's fixed size..... ChartsView *chartsView = [[ChartsView alloc]initWithFrame:CGRectMake(0, 0, 320, 800)]; self.scrollView.contentSize = chartsView.frame.size; [self.scrollView addSubview:chartsView]; } ```