我正在尝试在我的中绘制彩色文本UIView
子类。现在我正在使用单视图应用程序模板(用于测试)。除了以下内容外,没有任何修改drawRect:
method.
文本已绘制,但无论我将颜色设置为什么,它始终是黑色的。
- (void)drawRect:(CGRect)rect
{
UIFont* font = [UIFont fontWithName:@"Arial" size:72];
UIColor* textColor = [UIColor redColor];
NSDictionary* stringAttrs = @{ UITextAttributeFont : font, UITextAttributeTextColor : textColor };
NSAttributedString* attrStr = [[NSAttributedString alloc] initWithString:@"Hello" attributes:stringAttrs];
[attrStr drawAtPoint:CGPointMake(10.f, 10.f)];
}
我也尝试过[[UIColor redColor] set]
无济于事。
Answer:
NSDictionary* stringAttrs = @{ NSFontAttributeName : 字体,
NSForegroundColorAttributeName : 文本颜色 };
代替UITextAttributeTextColor
你应该使用NSForegroundColorAttributeName
。希望这可以帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)