Ketan Parmar Ketan Parmar - 1 year ago 164
iOS Question

How to resize text (font) to fit in UISegment of UISegmentedControl?

Is there any way to reduce font size that can be fit in single segment of


Have tried many thing something like,

[[UILabel appearanceWhenContainedIn:[UISegmentedControl class], nil] adjustsFontSizeToFitWidth];

[[UILabel appearanceWhenContainedIn:[UISegmentedControl class], nil] setMinimumScaleFactor:0.5];


NSArray *arr = segment.subviews; // segment is UISegmentedControl object

for (int i = 0; i < arr.count; i++) {

UIView *aSegment = [arr objectAtIndex:i];

for (UILabel *label in aSegment.subviews) {

if ([label isKindOfClass:[UILabel class]]) {

UILabel *myLabel = (UILabel *)label;

[myLabel setNumberOfLines:0];

label.numberOfLines = 0;
label.adjustsFontSizeToFitWidth = YES;
label.minimumScaleFactor = 0.5;


able to set number of lines of label of segment like,

[[UILabel appearanceWhenContainedIn:[UISegmentedControl class], nil] setNumberOfLines:0];

Can set single segment size as per content like,

segment.apportionsSegmentWidthsByContent = YES;

but every segment has different size in this case.

I want to keep same size of every segment and want to reduce font size that can be fit in
UISegmentLabel (label)
something like
. These properties is not working for label when contains in

If any one can help to achieve this, it will be appreciated!!

Thanks in advance!!

Answer Source

I found the issue, Actually it was my mistake!!! I was setting numberOfLines,adjustsFontSizeToFitWidth,minimumScaleFactor and TitleTextAttributes toghether. If we set titleTextAttribute then minimumScaleFactor can't work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download