iPhone - 使用 CGContext 在黑色 View 上绘制白色文本

标签 iphone cocoa-touch text colors core-graphics

我无法在drawRect方法中使用CGContext在黑色 View 上绘制一些白色文本。

我愿意:

CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextSetLineWidth(context, 1.0);
CGContextSelectFont(context, "Helvetica", 20, kCGEncodingMacRoman);
CGContextSetTextDrawingMode(context, kCGTextFill);

CGPoint center = self.center;

然后...
无法找到正确的方法。
我已经尝试过这个:

UIFont* font = [UIFont fontWithName:@"Geneva" size:12.0];
[@"Some text" drawAtPoint:center withFont:font];

但是它不起作用。

我没有找到任何 CGContext 方法。隐藏在哪里?

如何将文本绘制为白色?

最佳答案

好吧,经过几个小时阅读 Quartz 2D 编程指南后,我发现您还必须设置填充颜色,而不仅仅是描边颜色。所以下面的代码可以工作。

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

我需要在深灰色边框上显示图表标签。现在标签显示为白色。

关于iPhone - 使用 CGContext 在黑色 View 上绘制白色文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7251065/

相关文章:

ios - 将 Label 放入空的垂直 StackView 中会自动缩小堆栈

iphone - ARC 循环保留检测

ios - 无法使用 NSTimer 使 NSOperation 超时

iphone - 如何制作 UILabel 自动换行

iphone - 是否可以查看框架中 .m 文件中的源代码?

c# - 如何将一个文本文件拆分成多个文件?

Android 简单的 TextView 动画

iphone - 如何使用 iPhone 相机检查光线强度

iphone - iPhone开发时如何将文件放入xcode中的Documents文件夹中?

python - python中逐列求和两个文件