为什么CGContextSetRGBStrokeColor不是';你不在做ios7吗?
我有一个问题,使文本笔划在iOS7上工作…iOS4 iOS5和iOS6的一切都很好,但自从我为iOS7更新了我的设备后,我看不到笔划的颜色。有人知道这怎么可能吗 这是我的密码:为什么CGContextSetRGBStrokeColor不是';你不在做ios7吗?,text,colors,border,ios7,stroke,Text,Colors,Border,Ios7,Stroke,我有一个问题,使文本笔划在iOS7上工作…iOS4 iOS5和iOS6的一切都很好,但自从我为iOS7更新了我的设备后,我看不到笔划的颜色。有人知道这怎么可能吗 这是我的密码: UIGraphicsBeginImageContext(CGSizeMake(scale(line.position.width), scale(line.position.height))); CGContextRef context = UIGraphicsGetCurrentContext(); CGConte
UIGraphicsBeginImageContext(CGSizeMake(scale(line.position.width), scale(line.position.height)));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth (context, scale(4.0)); //4.0
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetBlendMode(context, kCGBlendModeScreen);
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
[label.text drawInRect:label.frame withFont:label.font];
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
注意到iOS7也出现了同样明显的回归,它不赞成使用字体API进行drawInRect。使用推荐的“withAttributes”风味是可行的
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:largeFont,NSFontAttributeName, [UIColor whiteColor],NSForegroundColorAttributeName,[UIColor blackColor], NSStrokeColorAttributeName,nil];
[myString drawAtPoint:myPosition withAttributes:dictionary];
我刚碰到这个。在iOS 7上,似乎使用CGContextSetRGBFillColor代替CGContextSetRGBStrokeColor来设置笔划颜色。看起来像只虫子。这意味着无法使用CGContextSetTextDrawingMode(上下文,kCGTextFillStroke);因为笔划颜色将与填充颜色相同 我通过添加第二个drawInRect调用修改了您的代码以使其正常工作。此解决方案也是向后兼容的,因为它只是额外重新笔划笔划,并且如果它们修复了错误,也应该是向前兼容的:
UIGraphicsBeginImageContext(CGSizeMake(scale(line.position.width), scale(line.position.height)));
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth (context, scale(4.0)); //4.0
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetBlendMode(context, kCGBlendModeScreen);
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1.0);
[label.text drawInRect:label.frame withFont:label.font];
//New Code Start
CGContextSetTextDrawingMode(context, kCGTextStroke);
CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
[label.text drawInRect:label.frame withFont:label.font];
//New Code End
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();