NSAttributedString 罢工属性不起作用
NSAttributedString Strike attribute not working
我知道这个问题已经被问过很多次了,但是 none 我阅读的答案帮助我解决了我的问题...
在我的 iOS 应用程序中,我正在使用默认框架 (UIGraphicsBeginPDFContextToFile...) 生成 PDF 文件。
一切正常,我可以更改文本颜色、底层样式等。
但我没能拨弦。
这是我的代码:
[toBeConfirmedText addAttributes:@{ NSBaselineOffsetAttributeName: @(0), NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick), NSStrikethroughColorAttributeName: [UIColor redColor] } range:NSMakeRange(0, toBeConfirmedText.length)];
但这不起作用...
有人有想法吗?
我应该在Xcode10中添加注释,你的代码没有问题。但是因为我需要添加测试代码,所以你可以将其视为答案。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"myTest.pdf"];
BOOL result = UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
UIGraphicsBeginPDFPage();
NSMutableAttributedString * toBeConfirmedText = [[NSMutableAttributedString alloc]initWithString:@"mytest"];
[toBeConfirmedText addAttributes:@{ NSBaselineOffsetAttributeName: @(0), NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick), NSStrikethroughColorAttributeName: [UIColor redColor] } range:NSMakeRange(0, toBeConfirmedText.length)];
[toBeConfirmedText drawInRect: CGRectMake(0, 0, 600, 200)];
UIGraphicsEndPDFContext();
我知道这个问题已经被问过很多次了,但是 none 我阅读的答案帮助我解决了我的问题...
在我的 iOS 应用程序中,我正在使用默认框架 (UIGraphicsBeginPDFContextToFile...) 生成 PDF 文件。 一切正常,我可以更改文本颜色、底层样式等。
但我没能拨弦。
这是我的代码:
[toBeConfirmedText addAttributes:@{ NSBaselineOffsetAttributeName: @(0), NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick), NSStrikethroughColorAttributeName: [UIColor redColor] } range:NSMakeRange(0, toBeConfirmedText.length)];
但这不起作用...
有人有想法吗?
我应该在Xcode10中添加注释,你的代码没有问题。但是因为我需要添加测试代码,所以你可以将其视为答案。
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"myTest.pdf"];
BOOL result = UIGraphicsBeginPDFContextToFile(filePath, CGRectZero, nil);
UIGraphicsBeginPDFPage();
NSMutableAttributedString * toBeConfirmedText = [[NSMutableAttributedString alloc]initWithString:@"mytest"];
[toBeConfirmedText addAttributes:@{ NSBaselineOffsetAttributeName: @(0), NSStrikethroughStyleAttributeName: @(NSUnderlineStyleThick), NSStrikethroughColorAttributeName: [UIColor redColor] } range:NSMakeRange(0, toBeConfirmedText.length)];
[toBeConfirmedText drawInRect: CGRectMake(0, 0, 600, 200)];
UIGraphicsEndPDFContext();