我已经通过代码创建了一个UIView,并希望在该视图上添加一些图像和描述。为此,我希望添加滚动视图,以便我们可以向下滚动以查看图像和描述。任何人都可以帮助我如何通过代码在UIView上方添加滚动视图。提前谢谢。
答案 0 :(得分:1)
嗨试试这个: -
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
scrollView.backgroundColor=[UIColor clearColor];
scrollView.showsHorizontalScrollIndicator = NO;
[scrollView setDelegate:self];
[scrollView setShowsVerticalScrollIndicator:NO];
[scrollView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:scrollView];
Now set the content size of scroll view:-
scrollView.contentSize = CGSizeMake(320, 600);//put values according to your requirements.
答案 1 :(得分:0)
UIScrollView *newView = [[UIScrollView alloc] initWithFrame:scrollFrame];
[newView setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[newView setDelegate:self];
[newView setBackgroundColor:backgroundColor];
[newView setPagingEnabled:YES];
[newView setShowsVerticalScrollIndicator:NO];
[newView setShowsHorizontalScrollIndicator:NO];
[[self view] addSubview:newView];
您可以设置Frame代替scrollFrame。
欢呼声
答案 2 :(得分:0)
实际上你可能不想创建UIView,你应该创建一个UIScrollView然后添加图像,并将其作为UIScrollView的子视图。那么你就可以滚动所有内容了。然后,您将按照您希望的方式设置UIScrollView。