[英]How to set text color when using drawInRect?
I have been using PaintCode to draw some of the graphics within my app, some of the drawn elements have text that is drawn using "drawInRect". 我一直在使用PaintCode在我的应用程序中绘制一些图形,一些绘制的元素具有使用“drawInRect”绘制的文本。 The text is always showing up black regardless of what I do to try and set the color. 无论我做什么尝试并设置颜色,文本总是显示为黑色。
here is the code where the text is created, and I am attempting to set the color: 这是创建文本的代码,我试图设置颜色:
//// Rounded Rectangle Drawing
UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(0, 0, 66, 66) cornerRadius: 15];
[[NPSColor NPSPrimaryColor] setFill];
[roundedRectanglePath fill];
UIFont *helveticaFont = [UIFont fontWithName:@"AvenirNextCondensed-Bold" size:50];
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
/// Set line break mode
paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
/// Set text alignment
paragraphStyle.alignment = NSTextAlignmentCenter;
NSDictionary *attributes = @{NSFontAttributeName:helveticaFont,
NSParagraphStyleAttributeName:paragraphStyle};
//// Text Drawing
CGRect textRect = CGRectMake(-4, -2.5, 74, 71.5);
[[NPSColor whiteColor] set];
[textContent drawInRect: CGRectInset(textRect, 0, 6) withAttributes:attributes];
}
The white color in the "text drawing" is what is not working properly. “文本绘图”中的白色是不能正常工作的。 Thanks for the assistance. 谢谢你的帮助。
You need to set the color of the text in the " attributes
" dictionary you pass in via: 您需要通过以下方式设置传入的“ attributes
”字典中文本的颜色:
[textContent drawInRect: CGRectInset(textRect, 0, 6) withAttributes:attributes];
My suggest would be: 我的建议是:
NSDictionary *attributes = @{ NSFontAttributeName:helveticaFont,
NSParagraphStyleAttributeName:paragraphStyle,
NSForegroundColorAttributeName: [NPSColor whiteColor]}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.