ios – 使用drawInRect时如何设置文本颜色?

ios – 使用drawInRect时如何设置文本颜色?,第1张

概述我一直在使用PaintCode在我的应用程序中绘制一些图形,一些绘制的元素具有使用“drawInRect”绘制的文本.无论我做什么尝试并设置颜色,文本总是显示为黑色. 这是创建文本的代码,我试图设置颜色: //// Rounded Rectangle Drawing UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathW 我一直在使用PaintCode在我的应用程序中绘制一些图形,一些绘制的元素具有使用“drawInRect”绘制的文本.无论我做什么尝试并设置颜色,文本总是显示为黑色.

这是创建文本的代码,我试图设置颜色:

//// Rounded Rectangle Drawing    UIBezIErPath* roundedRectanglePath = [UIBezIErPath bezIErPathWithRoundedRect: CGRectMake(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,6) withAttributes:attributes];}

“文本绘图”中的白色是不能正常工作的.谢谢你的帮助.

@H_403_8@@R_419_6120@ 您需要通过以下方式设置传入的“属性”字典中文本的颜色:
[textContent drawInRect: CGRectInset(textRect,6) withAttributes:attributes];

我的建议是:

NSDictionary *attributes = @{ NSFontAttributename:helveticaFont,NSParagraphStyleAttributename:paragraphStyle,NSForegroundcolorAttributename: [NPScolor whitecolor]}
@H_403_8@ @H_403_8@ 总结

以上是内存溢出为你收集整理的ios – 使用drawInRect时如何设置文本颜色?全部内容,希望文章能够帮你解决ios – 使用drawInRect时如何设置文本颜色?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1099099.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存