Change width of a segmented control based on titles in each segment?

Thromordyn picture Thromordyn · Aug 16, 2012 · Viewed 16.7k times · Source

Starts like this, which I like:
Screenshot1.png

But then I add a segment and this happens:
Screenshot2.png The width is set in IB, not in code.

All I need is a method to calculate width on the fly. At the end, it would do something like this:

control.width = (labelWidths + marginWidths);
// where marginWidths = (marginWidth * control.numberOfSegments)

Answer

Rajesh picture Rajesh · Jul 17, 2015

You can use the propertyapportionsSegmentWidthsByContent and set it toYES.