gpt4 book ai didi

objective-c - 为什么这段代码不绘制白色文本?

转载 作者:行者123 更新时间:2023-12-03 17:34:59 25 4
gpt4 key购买 nike

此代码不绘制白色文本,为什么?

NSMutableParagraphStyle* style = [[NSMutableParagraphStyle alloc] init];
[style setAlignment:NSCenterTextAlignment];
NSFont *font = [NSFont fontWithName:@"System" size:13];
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:style, NSParagraphStyleAttributeName, font, NSFontAttributeName, [NSColor whiteColor], NSForegroundColorAttributeName, nil];

[button.title drawInRect:textRect withAttributes:attrs];

最佳答案

(假设[cocoa]标签并不意味着cocoa touch)

这是因为当再次调用 -drawRect: 时,NSButton 可能会覆盖您绘制文本的选择。您可以将在该字典中给出的属性应用于 NSAttributedString 并调用 setAttributedTitle: 以保留您的样式选择。

如果您需要对文本渲染进行更细粒度的控制,请编辑逻辑并将其移动到 -drawRect: 中(如果尚不存在),或者根据需要提供 NSTextField 或 NSTextView。

您提供的代码的主要问题是@“System”不是字体名称。

关于objective-c - 为什么这段代码不绘制白色文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15305692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com