Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用Apple'更改文本和背景色;PDFKit框架_Ios_Objective C_Swift_Macos_Pdf - Fatal编程技术网

Ios 使用Apple'更改文本和背景色;PDFKit框架

Ios 使用Apple'更改文本和背景色;PDFKit框架,ios,objective-c,swift,macos,pdf,Ios,Objective C,Swift,Macos,Pdf,我想更改显示的PDF文档的文本和背景色,以夜间模式显示文档(暗背景、浅前景等) 我知道有一个方法,可以在子类中覆盖以添加效果(如水印,如中所示),但我不知道如何设置颜色属性 有没有一种方法可以通过PDFKit库或Apple的任何其他低级API(Quartz)实现这一点?为pdf中的文本提供颜色,您可以使用 -(CGRect)addText:(NSString*)text withFrame:(CGRect)frame font:(NSString*)fontName fontSize:(floa

我想更改显示的PDF文档的文本和背景色,以夜间模式显示文档(暗背景、浅前景等)

我知道有一个方法,可以在子类中覆盖以添加效果(如水印,如中所示),但我不知道如何设置颜色属性


有没有一种方法可以通过PDFKit库或Apple的任何其他低级API(Quartz)实现这一点?

为pdf中的文本提供颜色,您可以使用

-(CGRect)addText:(NSString*)text withFrame:(CGRect)frame font:(NSString*)fontName fontSize:(float)fontSize andColor:(UIColor*)color{
    const CGFloat *val = CGColorGetComponents(color.CGColor);

    CGContextRef    currentContext = UIGraphicsGetCurrentContext();
    CGContextSetRGBFillColor(currentContext, val[0], val[1], val[2], val[3]);
    UIFont *font =  [UIFont fontWithName:fontName size:fontSize];
    CGSize stringSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(pageSize.width - 2*20-2*20, pageSize.height - 2*20 - 2*20) lineBreakMode:NSLineBreakByWordWrapping];

    CGRect renderingRect = CGRectMake(frame.origin.x, frame.origin.y, textWidth, stringSize.height);

    [text drawInRect:renderingRect withFont:font lineBreakMode:NSLineBreakByWordWrapping alignment:NSTextAlignmentLeft];

    frame = CGRectMake(frame.origin.x, frame.origin.y, textWidth, stringSize.height);

    return frame;
}
对于背景色,请使用以下选项

CGContextRef currentContext = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(currentContext, [UIColor blueColor].CGColor );
    CGContextFillRect(currentContext, CGRectMake(0, 110.5, pageSize.width, pageSize.height));

你在上下文中自己绘制文本吗?你能发布一些你在这个方法中所做的代码吗?我看到在PDFPage中存在NSAttributedString属性字符串。我不想在页面上绘制任何新内容,我只想在夜间模式下显示现有文档(深色背景和浅色前景)。有点像AdobeReader:你有没有找到在pdfpage中应用夜间模式或反转颜色的方法?我们公司决定使用另一个工具包(Foxit Mobile SDK for iOS),它通过一个方法调用就支持开箱即用的夜间模式。但对于苹果的SDK:不,我仍然不知道如何实现同样的功能。这个方法应该放在哪里,谁来称呼它?