gpt4 book ai didi

macos - NSTabViewItem 中的水平居中标签

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

我创建了 NSTabViewItem 的子类,以便我可以为选项卡 View 项指定特定宽度,如 this answer 中所示。这运行良好,但是选项卡的标签未水平居中,因此文本右侧有额外的填充。如何将文本在标签边界内居中,或者如何将文本在固定宽度 NSTabViewItem 内正确居中?

enter image description here

最佳答案

您可以重写“drawLabel:inRect:”函数并在此处给出适当的绘制矩形。喜欢

 (void)drawLabel:(BOOL)shouldTruncateLabel
inRect:(NSRect)labelRect{
//find your label size
NSDictionary* attr = [NSDictionary dictionaryWithObjectsAndKeys:
self.tabView.font,NSFontAttributeName,
nil];
NSSize labelSize = [self.label sizeWithAttributes:attr];
//modify your labelRect here.....
labelRect.origin.x += floor((labelRect.size.width - labelSize.width)/2)
labelRect.size.width = labelSize.width;
//call super
[super drawWithFrame:shouldTruncateLabel inRect:labelRect];
}

关于macos - NSTabViewItem 中的水平居中标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29269374/

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