2014-01-17 4 views
1

ios에서 epub reader를 만들고 있습니다. 나는 uiwebview에 epub를 보여줄 수 있지만, epub doest의 크기는 uiwebview에 맞지 않습니다. epub 파일이 webview에서 더 크고 비례하지 않는 것으로 보입니다. 크기를 조정하려면 어떻게해야합니까? 감사..epub에서 pagebreak가 uiwebview에서 작동하지 않습니다. iOS

이것은 내 코드입니다.

vCover = [UIView의 ALLOC] initWithFrame : CGRectMake (0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];

CGRect frame = busyLoad.frame; 
frame.origin.x = self.view.frame.size.width/2 - frame.size.width/2; 
frame.origin.y = self.view.frame.size.height/2 - frame.size.height/2; 
busyLoad.frame = frame; 


[self.view addSubview:vCover]; 
[self.view bringSubviewToFront:vCover]; 
[self.view addSubview:busyLoad]; 
[self.view bringSubviewToFront:busyLoad]; 
[busyLoad startAnimating]; 
int offset = [[NSString stringWithFormat:@"%@", todo.htmOffset]intValue]*webView.bounds.size.height; 

NSLog(@"pageH:%f ", webView.bounds.size.height); 

UIScrollView *scrollview = (UIScrollView *)[webView.subviews objectAtIndex:0]; 
scrollview.contentInset  = UIEdgeInsetsMake(44.0,0.0,44.0,0.0); 
NSString* javascript = [NSString stringWithFormat:@"window.scrollBy(0, %d);", offset]; 
[webView stringByEvaluatingJavaScriptFromString:javascript]; 
NSString *padding = @"document.body.style.margin='50';"; 
[webView stringByEvaluatingJavaScriptFromString:padding]; 
NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule('body', '-webkit-text-size-adjust: %d%%;')", 100]; 
[webView stringByEvaluatingJavaScriptFromString:setTextSizeRule]; 
NSLog(@"DidLoad:%d", offset); 

[webView setHidden:NO]; 



[busyLoad removeFromSuperview]; 
[vCover removeFromSuperview]; 
[busyLoad stopAnimating]; 
+2

당신은 당신이 안녕 응답에 감사드립니다있는 UIWebView – Retro

+0

로 파일을 설정하는 방법을 공유 할 수 있습니다! 나는 uiwebview에서 페이지 나누기가 항상 작동하지 않는다는 것을 알게되었습니다. 나는 ibooks에서 제대로 읽을 수있는 샘플 epub 책을 가지고 있습니다. 감사. – user3205472

+0

안녕하세요 @ user3205472 iOS의 UIWebView에서 book.html 파일의 페이지를 깨뜨리는 방법을 알려주세요. – BADRI

답변

1

안녕하세요!,

당신은있는 UIScrollView 의 iOS7에 페이지 매김 속성 같은 페이지 매김을 할 수있는 (즉 webview.scrollview.pagingEnabled = 예) 방법을 아래에 사용.

- (void)webViewDidFinishLoad:(UIWebView *)webView 
    { 
    [self setPagination:self]; 
    } 

    - (void) setPagination:(UIWebView *) webView 
    { 
     NSString *varMySheet = @"var mySheet = document.styleSheets[0];"; 

     NSString *addCSSRule = @"function addCSSRule(selector, newRule) {" 
     "ruleIndex = mySheet.cssRules.length;" 
     "mySheet.insertRule(selector + '{' + newRule + ';}', ruleIndex);" // For Firefox, Chrome, etc. 
     "}"; 

     NSString *insertRule1 = [NSString stringWithFormat:@"addCSSRule('html', 'height: %fpx; -webkit-column-gap: 0px; -webkit-column-width: %fpx;')", webView.frame.size.height, webView.frame.size.width]; 
     NSString *insertRule2 = [NSString stringWithFormat:@"addCSSRule('p', 'text-align: justify;')"]; 

     [webView stringByEvaluatingJavaScriptFromString:varMySheet]; 

     [webView stringByEvaluatingJavaScriptFromString:addCSSRule]; 

     [webView stringByEvaluatingJavaScriptFromString:insertRule1]; 

     [webView stringByEvaluatingJavaScriptFromString:insertRule2]; 


     CGSize contentSize = CGSizeMake([[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollWidth;"] floatValue], 
             [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"] floatValue]); 
     int pageCount = contentSize.width/webView.frame.size.width; 

    //move to page using offset 
    //   CGPoint point = CGPointMake(0, 0); 
    //   point = CGPointMake(indexOfPage*webView.frame.size.width, 0); 
    //   self.scrollView.contentOffset = point; 

    }