1

I have this NSSegmentedControl created on interface builder and saved on a xib file. The control has initially 4 segments.

If I use this

[self.myControl setSegmentCount:6];

to increase the number of segments to 6, programmatically, it will not work but if I do

[self.myControl setSegmentCount:2];

to reduce the number of segments to 2, it works.

if after that I return the number of segments to 4, it works, but I cannot pass the number of segments defined on interface builder.

Any clues?

Duck
  • 34,902
  • 47
  • 248
  • 470
  • Are you sure the segments aren't being clipped or that there's enough room for them? You should try enabling auto sizing for them – Luke Aug 01 '14 at 03:31
  • how do I do that on interface builder? – Duck Aug 01 '14 at 03:32
  • I've never used NSSegmentedControl but I think if you can select an individual segment in interface builder, you can then click on the little ruler icon in the right hand sidebar and there should be autosizing options there – Luke Aug 01 '14 at 03:56
  • that's it. Your comment lead me to the answer that is the lack of constraints on the control. Add your comment as an answer and I will accept that. Thanks. – Duck Aug 01 '14 at 03:58
  • Actually I just read the NSSegmentedControl documentation and if you set the width of a segment to 0, it will automatically resize it to fit the contents – Luke Aug 01 '14 at 03:59

1 Answers1

2

Select a segment in interface builder and click on the little ruler in the right hand sidebar to add layout constraints and prevent clipping

Luke
  • 4,908
  • 1
  • 37
  • 59