gpt4 book ai didi

macos - NSTextField 上奇怪的字体行为

转载 作者:行者123 更新时间:2023-12-03 16:43:41 26 4
gpt4 key购买 nike

我以编程方式将 NSTextField 添加到我的 NSView 中:

NSTextField *projectLabel = [[NSTextField alloc] initWithFrame:frame];
[projectLabel setStringValue:@"projectName"];
[projectLabel setBezeled:NO];
[projectLabel setDrawsBackground:NO];
[projectLabel setEditable:NO];
[projectLabel setSelectable:NO];

[projectLabel setFont:[NSFont controlContentFontOfSize:13]];
projectLabel.autoresizingMask = NSViewMaxXMargin | NSViewMinYMargin;

[self addSubview:projectLabel];
[self setAutoresizesSubviews:NO];

此字段已正确添加,但是当我更改 View 大小(甚至将窗口移动到第二个显示器)时,字段上的字体变化非常奇怪(参见附图)。

开始时before
更改尺寸后after
我不知道我做错了什么

最佳答案

I drew this label on drawRect every time, when the size changes.

那么,您要手动告诉字段在其父 View 的 drawRect: 中显示?

不要那样做。它是一个 subview ,所以无论如何它都会被告知依次绘制。就让它发生吧。

关于macos - NSTextField 上奇怪的字体行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8713214/

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