有没有人找到**合法**覆盖来自定义NSTabView的绘图?



BGHUDAppKit BGHUDTabView _drawThemeTab私有 API 覆盖现已损坏

多年来,我一直在使用最初基于 BGHUDAppKit 的代码,并找到了 BGHUDAppKit 覆盖的所有私有 API 的替代品。

除了一个我找不到替代方法

的...
-[NSTabView _drawThemeTab:withState:inRect:]

(注意:我也在很多情况下使用古老的PSMTabBarControl,所以如果所有其他方法都失败了,我会将所有选项卡视图转换为PSMTabBarControl(

苹果现在已经在10.14 Mojave中添加了黑暗的NSAppearance(所以在~10年内,一旦我们停止支持High Sierra,我就可以使用它(。

无论苹果公司哪个自私的开发人员写NSTabView都不相信使他的视图可定制,不像所有其他可定制的NSControls。 以下是NSTabView自定义绘图的黑客覆盖的一部分:

// until we can eliminate private API _drawThemeTab:, return nil for new NSAppearance
- (id) appearance { return nil; }
- (id) effectiveAppearance  { return nil; }
-(void)_drawThemeTab:(id) tabItem withState:(NSUInteger) state inRect:(NSRect) aRect {
NSInteger idx = [self indexOfTabViewItem: tabItem];
int gradientAngle = 90;
NSBezierPath *path = nil;
aRect = NSInsetRect(aRect, 0.5f, 0.5f);
if([self tabViewType] == NSLeftTabsBezelBorder) {
gradientAngle = 0;
} else if([self tabViewType] == NSRightTabsBezelBorder) {
gradientAngle = 180;
}
NSColor *specialFillColor = [tabItem color];
NSColor *outlineColor = nil;
NSString *name = [specialFillColor description];
// MEC - added new prefix 12/15/17 to fix white border around last segment in High Sierra
if ( [name hasPrefix:@"NSNamedColorSpace System"] || [name hasPrefix:@"Catalog color: System controlColor"])
specialFillColor = nil;
else if ( [name isEqualToString: @"NSCalibratedWhiteColorSpace 0 1"] )
[specialFillColor set];
else
{
outlineColor = specialFillColor;
specialFillColor = nil;
}
... etc ...

最好完全禁用 NSTabView 的绘制(将其tabViewType设置为NSNoTabsNoBorder(,并创建自定义分段条形图以单独绘制所选内容(作为同级视图(。这允许您完全控制该自定义实现的外观、布局和大小,而不是依赖于 NSTabView 的任何详细信息。

查看 NSTabViewController 的视图层次结构,您可以看到它具有相同的方法,通过将 NSSegmentedControl 用作单独的子视图来管理来自 NSTabView 的选择。

最新更新