开发者

How do I change the truncation method or width on the popup of a NSComboBox

The truncation can开发者_JAVA百科 be easily set for the main text area but the popup does not do any truncation, with similar paths, users cannot tell which path is which.

or is the a way to change the width of the popup list to match the longest string so that truncation is not needed?


There is no official way to do this, unfortunately.

There is a way to do it which, though it doesn’t use any private methods, relies on the way NSComboBoxes are implemented internally, and that could change at any time. This would probably would not be acceptable in the App Store.

If you subclass NSComboBoxCell and implement the NSTableViewDelegate method tableView:willDisplayCell:forTableColumn:row:, you can modify the text cell before it is displayed in the combo box’s popup window.

- (void)tableView:(NSTableView *)tableView
        willDisplayCell:(NSCell *)cell
        forTableColumn:(NSTableColumn *)tableColumn
        row:(NSInteger)rowIndex
{
   [cell setTruncatesLastVisibleLine:YES];
   [cell setLineBreakMode:NSLineBreakByTruncatingMiddle];
}

This works because the popup list is implemented internally with an NSTableView, and the table view’s delegate is set to the popup cell.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜