2014-09-05 31 views
0

我正在使用一個開源PDF查看庫(VFR PDF閱讀器https://github.com/vfr/Reader)。我試圖用白色文本實現「夜間模式」或黑色背景。我可以將背景變爲任何我喜歡的顏色,但無法改變文字顏色。您可以在「drawLayer」方法中看到您可以在https://github.com/vfr/Reader/blob/master/Sources/ReaderContentPage.m修改背景顏色的位置。它只是簡單地改變PDF渲染矩形的顏色。如何在iOS上使用CoreGraphics呈現pdf上的文字顏色?

我的問題是:有什麼我可以做的「上下文」,將導致PDF中的文本改變顏色(在我的情況下,我想白色文本)?在這個行看起來是這樣的(線558):

CGContextDrawPDFPage(context, _PDFPageRef); // Render the PDF page into the context 

回答

1

這裏是我解決了夜視:

1)我跟蹤用戶偏好(夜間模式或白天模式)的NSUserDefault

2)

- (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context 
{ 

一個)檢索所述用戶偏好

NSString *userViewMode = [[NSUserDefaults standardUserDefaults] objectForKey:@"DayOrNightSetting"]; 

b)中設定的CGContextRef的回地面顏色爲白色

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor); 

C)替換CGContextDrawPage(上下文,_PDFPageRef)其中:

if ([userViewMode isEqualToString:@"Night"]) { 
     CGContextSetBlendMode(context, kCGBlendModeDestinationAtop); 

     CGContextDrawPDFPage(context, _PDFPageRef); 
     CGContextSetBlendMode(context, kCGBlendModeExclusion); 
     CGContextDrawPDFPage(context, _PDFPageRef); 
    } 
    else 
    { 
     CGContextSetBlendMode(context,kCGBlendModeNormal); 
    CGContextDrawPDFPage(context, _PDFPageRef); 
    } 
+0

我使用的上面提到的代碼,但得到一些特定PDF頁面的問題,這能夠隱藏許多黑色背景和白色文本但不是全部的頁面。你有什麼主意嗎 ? 對於某些頁面,它使背景灰色而不是黑色 – 2016-02-13 06:31:30

相關問題