1

If I add a number of NSTabViewItems to an NSTabViewController, the tab view item buttons are sized according to the length of the label text. With different texts for each label this can result in NSTabViewItem buttons that have vastly different sizes.

Is there a way to set the button sizes/widths to a specific size in IB? Can it be done dynamically in code?

4

1 回答 1

0

我不认为这可以在 Interface Builder 中完成,但您应该能够继承 NSTabViewItem 并覆盖- (NSSize)sizeOfLabel:(BOOL)computeMin以返回所需的值。更多信息在这里

例如,如果您想要所有相同 100 pt 宽度的 NSTabViewItem:

@interface MyTabViewItem : NSTabViewItem
@end

@implementation MyTabViewItem
- (NSSize)sizeOfLabel:(BOOL)computeMin {

    NSSize size = [super sizeOfLabel:computeMin];
    size.width = 100.0
    return size;

}
@end

当然,您需要将 NSTabView 的项目设置为 MyTabViewItem 的实例(在 IB 中或在代码中动态添加它们时)。

于 2015-03-09T14:56:01.783 回答