Macos 如何更改工具提示的字体、大小和包装?
我有一个基于单元格的NSTableView,我正在使用标准的NSTableViewDelegate方法为行设置工具提示:Macos 如何更改工具提示的字体、大小和包装?,macos,cocoa,Macos,Cocoa,我有一个基于单元格的NSTableView,我正在使用标准的NSTableViewDelegate方法为行设置工具提示: - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex mouseLocation:(NS
- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex mouseLocation:(NSPoint)mouseLocation
{
if (aTableView == scriptBlocksTableView)
{
std::vector<SLiMEidosBlock*> &scriptBlocks = sim->script_blocks_;
int scriptBlockCount = (int)scriptBlocks.size();
if (rowIndex < scriptBlockCount)
{
SLiMEidosBlock *scriptBlock = scriptBlocks[rowIndex];
const char *script_string = scriptBlock->compound_statement_node_->token_->token_string_.c_str();
NSString *ns_script_string = [NSString stringWithUTF8String:script_string];
// change whitespace to non-breaking spaces; we want to force AppKit not to wrap code
ns_script_string = [ns_script_string stringByReplacingOccurrencesOfString:@" " withString:@" "]; // second string is an
ns_script_string = [ns_script_string stringByReplacingOccurrencesOfString:@"\t" withString:@" "]; // second string is three s
return ns_script_string;
}
}
return nil;
}
这是Objective-C++代码,但这对问题并不重要。我想显示的工具提示是一小段代码。我希望它显示在一个小的单空格字体摩纳哥9?,我希望行不包装。正如您所看到的,我在这里用不间断的空格替换空格和制表符,以防止换行,这是有效的,但仅在一定程度上有效。如果一行太长,AppKit将强制换行,即使没有有效的换行点;它只是强制执行一个最大的工具提示宽度
我找不到任何方法来更改工具提示的字体/大小,或强制它们不换行。我确实发现了影响工具提示的默认设置;我甚至没有尝试过这些,因为应用程序范围内的默认设置是不可接受的,因为我的应用程序还有其他工具提示,我想正常运行。本文确实建议所需的机械设备在AppKit的引擎盖下;我只需要一个API
我猜答案是对不起,你运气不好。在这种情况下,是否有人有任何好的自定义工具提示显示代码,可能使用弹出窗口或无边框窗口或类似的代码,他们愿意共享?理想情况下,它将模仿标准Cocoa工具提示的外观和行为,但添加这种可配置性。或者有人有其他解决方案吗?工具提示是否与单元格内容相同,只是没有被截断?也就是说,您正在寻找扩展工具提示吗?或者,即使不一样,也可以使用自定义单元格来自定义大小和绘制展开工具提示。不,工具提示与表行中显示的不同。