[英]Add scrollview iOS Objective-C
我的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"];
所有這些都完全適合視圖。 我知道需要在底部添加一個額外的textView,因此需要用戶能夠滾動查看它。 如何將此信息添加到可滾動視圖並添加其他textView?
您可以讓UIViewController擴展UISCrollViewController。 或者,您可以在viewDidLoad
方法中將UIScrollView添加到視圖控制器的視圖中。 然后將視圖的所有子視圖添加到滾動視圖。
self.scrollView = [[UIScrollView all] initWithFrame:self.view.bounds]
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.width, HEIGHT_OF_SCROLLABLE_AREA).
如果您的上一個textview名為lastTextView
我也將對滾動視圖高度執行類似的lastTextView
HEIGHT_OF_SCROLLABLE_AREA = CGRectGetMaxY(lastTextView.frame + bottomPadding)
您確定拖動了滾動視圖上的所有其他視圖嗎? 確保滾動視圖的contentSize足夠高(您知道,高於屏幕)可以滾動。
您是否設置了UIScrollView的委托。 如果您尚未設置UIScrollView的委托,則也可能滾動無法正常工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.