Reputation: 101
In a pdf file using UIWebView, I need to scroll horizontally instead of vertically. I have created UIScrollView in the form:
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.contentSize = CGSizeMake(2000, 420);
scrollView.bounces = NO;
scrollView.alwaysBounceHorizontal = NO;
scrollView.alwaysBounceVertical = NO;
scrollView.backgroundColor = [UIColor whiteColor];
and now adding the UIWebView
in to UIScrollView as
[scrollView addSubview:webView];
it is not displaying the pdf file but if i give code like this
[self.view addSubview:webView];
now it displays the file but it vertical scroll
I need to make it to scroll horizontally please help me. Thanks in advance.
Upvotes: 4
Views: 2896
Reputation: 138
You can straight away put the pdf on UIWebView and if it is multiple pages it will scroll automatically. You can try the code below
UIWebView *webView = [[UIWebview alloc]init];
webView.frame = "SET FRAME"
[self.view addSubView:webView];
// create a URL for the pdf file which is in you project
NSURL *pdfURL = [[NSBundle mainBundle]URLForResource:"Name of pdf" withExtension:@"pdf"];**
[webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
//just to show the scroll indicators
[webView.scrollView flashScrollIndicators];
I do it this way....
Upvotes: 0
Reputation: 280
After your code:
UIScrollView *scrollView = [[UIScrollView alloc] init];
scrollView.contentSize = CGSizeMake(2000, 420);
scrollView.bounces = NO;
scrollView.alwaysBounceHorizontal = NO;
scrollView.alwaysBounceVertical = NO;
scrollView.backgroundColor = [UIColor whiteColor];
[scrollView addSubview:webView];
add this also:
[self.view addSubview:scrollView];
if you have not added it earlier.
Upvotes: 1