How to change height of NSSegmentedControl
Asked Answered
B

1

6

I'm trying to increase the height of a NSSegmentedControl, beyond the 25px "Regular" control size. I subclassed NSSegmentedCell, I understand that i have 2 methods to work with.

- (void)drawSegment:(NSInteger)segment
            inFrame:(NSRect)frame
           withView:(NSView *)controlView

- (void)drawWithFrame:(NSRect)frame
               inView:(NSView *)view

If I place a segmented control in IB then override the above methods in my NSSegmentedCell subclass. As excepted the frame and view that are passed in are based on the height of the segmented control in IB. So, Im not sure where to go from here.

Do I have to subclass NSSegmentedControl as well and draw my own control at my required height? and then use the NSSegmentedCell subclass to handle the segments?

Bennie answered 13/8, 2014 at 15:15 Comment(4)
I am haven the same problem. How did you do it in the end?Blackness
@Daniel, unfortunately, I never did find a solution for this, i ended up sticking with the default height.Bennie
I ended up doing my own SegmentedControl made out of NSButtons. It needs some cleanup and then I'll post on Github. It is basically a copy of what you can see in Pages or Keynote at the top of the sidebar when you select an image.Blackness
Out of curiosity, why change the height? I'd like to see what the ideal outcome might look likeStarflower
S
1

The default NSSegmentedControl does not allow you to adjust its drawn height. To do this, you will have to subclass it (and NSSegmentedCell) and override its drawing functions with your own.

Starflower answered 19/10, 2016 at 20:0 Comment(1)
You can probably also do some nastiness with applying scaling transformations to the control's core animation layer, but I guarantee it won't look goodStarflower

© 2022 - 2024 — McMap. All rights reserved.