简体   繁体   English

添加scrollview iOS Objective-C

[英]Add scrollview iOS Objective-C

I have the following code in viewDidLoad on my ViewController: 我的ViewController的viewDidLoad中有以下代码:

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:204.0/255 green:00.0/255 blue:00.0/255 alpha:1];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]]; 

autoNameLabel.text = (NSString *)[vendorDetails objectForKey:@"autoname"];
homeLabel.text = (NSString *)[vendorDetails objectForKey:@"homelab"];
descriptionTextView.text = (NSString *)[vendorDetails objectForKey:@"description"];

This all fits perfectly on the view. 所有这些都完全适合视图。 I know need to add an additional textView on the bottom so need the user to be able to scroll to see it. 我知道需要在底部添加一个额外的textView,因此需要用户能够滚动查看它。 How can I add this info to a scrollable view and add my additional textView? 如何将此信息添加到可滚动视图并添加其他textView?

you could have your UIViewController extend UISCrollViewController. 您可以让UIViewController扩展UISCrollViewController。 Or you could add a UIScrollView to your view controller's view in the method viewDidLoad . 或者,您可以在viewDidLoad方法中将UIScrollView添加到视图控制器的视图中。 Then add all subviews of your view to the scrollview instead. 然后将视图的所有子视图添加到滚动视图。

self.scrollView = [[UIScrollView all] initWithFrame:self.view.bounds]
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.width, HEIGHT_OF_SCROLLABLE_AREA).

I would also do something like this for the scroll view height if your last textview is named lastTextView 如果您的上一个textview名为lastTextView我也将对滚动视图高度执行类似的lastTextView

HEIGHT_OF_SCROLLABLE_AREA = CGRectGetMaxY(lastTextView.frame + bottomPadding)

Are you sure you dragged all the other views on the scrollview? 您确定拖动了滚动视图上的所有其他视图吗? Make sure the contentSize of the scrollview is high enough(you know, higher than the screen) to scroll. 确保滚动视图的contentSize足够高(您知道,高于屏幕)可以滚动。

have u set delegate of UIScrollView. 您是否设置了UIScrollView的委托。 if you have not set delegate of UIScrollView then also it may possible that your scroll is not working. 如果您尚未设置UIScrollView的委托,则也可能滚动无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM