我试图在 aUIWebView
而不是 a中绘制内容UIView
,因为我喜欢UIWebView
通过捏合来放大和缩小的能力。这是我的代码:
// setup environment
CGRect outputRect = myWebView.bounds;
CFMutableDataRef data = CFDataCreateMutable(NULL, 0); // init with default allocator and unlimited size
CGDataConsumerRef dataConsumer = CGDataConsumerCreateWithCFData(data);
CGContextRef pdfContext = CGPDFContextCreate(dataConsumer, &outputRect, NULL);
CGPDFContextBeginPage(pdfContext, NULL);
// draw something
CGContextSetRGBFillColor (pdfContext, 1, 0, 0, 1);
CGContextFillRect (pdfContext, CGRectMake (0, 0, 200, 100 ));
CGContextSetRGBFillColor (pdfContext, 0, 0, 1, .5);
CGContextFillRect (pdfContext, CGRectMake (0, 0, 100, 200 ));
CGPDFContextEndPage(pdfContext);
// load drawing in webView
[myWebView loadData:(NSData *)data MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
// cleanup
if(data != NULL) CFRelease(data); // always make sure to not pass NULL in CFRelease
CGDataConsumerRelease(dataConsumer);
CGContextRelease(pdfContext);
UIWebView
在我想要看到的其他事情的背后,所以我让UIWebView
's 背景透明,如下所示:
myWebView.opaque = NO; //otherwise setting background color has no effect
myWebView.backgroundColor = [UIColor clearColor];
如果我不加载 pdf,这可以正常工作。但是,当 pdf 加载时,其页面有白色背景和阴影,如下面的屏幕截图所示。这搞乱了我的 UI 设计。如何摆脱阴影并使pdf页面透明?
谢谢