简体   繁体   English

iOS 7.1 NSString drawInRect

[英]iOS 7.1 NSString drawInRect

I have a code which worked just fine until I built my project with iOS 7.1. 在使用iOS 7.1构建项目之前,我的代码工作得很好。 Before, the text correctly showed on PDF page. 以前,文本正确显示在PDF页面上。

[strSomeText drawInRect:rectForText withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, mutParagraphStyle, NSParagraphStyleAttributeName, colorRed, NSForegroundColorAttributeName, nil]];

But now, everything in formatting dictionary is being disregarded. 但是现在,格式化字典中的所有内容都被忽略了。 The PDF document shows black text of default font and size. PDF文档显示默认字体和大小的黑色文本。

Thank you for responses. 感谢您的回应。

I would try using an NSAttributedString and find whether this works. 我会尝试使用NSAttributedString并查找是否NSAttributedString I do not have a good reason as to why your code has stopped working, but try this: 对于您的代码为何停止工作,我没有充分的理由,但是请尝试以下操作:

//    obviously these variables are examples, keep whatever variables you are using
UIFont *font = [UIFont fontWithName:@"whatever_font" size:16.0f];
NSParagraphStyle *paragraphStyle = [NSParagraphStyle defaultParagraphStyle];

NSDictionary *attributes = @{NSFontAttributeName : font, NSParagraphStyleAttributeName : paragraphStyle, NSForegroundColorAttributeName : [UIColor redColor]};

NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:exampleString attributes:attributes];

[attributedString drawInRect];

You can try this: 您可以尝试以下方法:

UIGraphicsPushContext(ctx);

[strSomeText drawInRect:rectForText withAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, mutParagraphStyle, NSParagraphStyleAttributeName, colorRed, NSForegroundColorAttributeName, nil]];

UIGraphicsPopContext();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM