简体   繁体   中英

Add scrollview iOS Objective-C

I have the following code in viewDidLoad on my ViewController:

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. How can I add this info to a scrollable view and add my additional textView?

you could have your UIViewController extend UISCrollViewController. Or you could add a UIScrollView to your view controller's view in the method viewDidLoad . 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

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.

have u set delegate of UIScrollView. if you have not set delegate of UIScrollView then also it may possible that your scroll is not working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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