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?

Yohst
  • 1,671
  • 18
  • 37
  • Did you ever figure out how to do this? I noticed that the Spark email app has done some kind of wizardry to make their preference tabs spaced and padded equally: http://d.pr/i/25AX – Clifton Labrum Feb 14 '17 at 19:12
  • nope, sorry, was long time ago ;-) – Yohst Feb 16 '17 at 14:28

1 Answers1

0

I don't think this can be done in Interface Builder, but you should be able to subclass NSTabViewItem and override - (NSSize)sizeOfLabel:(BOOL)computeMin in order to return desired value. More info here.

For instance, if you want all NSTabViewItem of same 100 pt width:

@interface MyTabViewItem : NSTabViewItem
@end

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

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

}
@end

and, of course, you'll need to set your NSTabView's items to be instance of MyTabViewItem (either in IB or when dynamically adding them in your code).

mzf
  • 420
  • 3
  • 8
  • Yes I tried that but this just changes the label size. Adjusting the label size pushes out the tabviewitem's frame but it cannot be set directly. I.e., the height cannot be adjusted. Additionally, width is determined by label size + a margin (what ever that is). So in my opinion, adjusting labelSize is not really equivalent to being able to make direct tabView item changes. – Yohst Mar 10 '15 at 01:43
  • Your question title is quite misleading, as it explicitly mentions "button labels". Label height can be adjusted as well: simply return a `NSSize` struct with desired height. This however won't solve tab padding issue. – mzf Mar 10 '15 at 09:38