How to change text font size in UISegmentedControl?

Below is the initialization code of my UISegmentedControl .

 - (void)initializeToolButtons { NSArray *buttonTitles = [NSArray arrayWithObjects:@"ANNEXET", @"HOVET", @"GLOBEN", "ALL", nil]; toolbuttons = [[UISegmentedControl alloc] initWithItems:buttonTitles]; toolbuttons.segmentedControlStyle = UISegmentedControlStyleBar; toolbuttons.tintColor = [UIColor darkGrayColor]; toolbuttons.backgroundColor = [UIColor blackColor]; toolbuttons.frame = CGRectMake(0, 0, 320, 30); [toolbuttons addTarget:self action:@selector(toolButtonsAction) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:toolbuttons]; } 

How to reduce the font size for each element in a UISegmentedControl ?

Note. toolButtons already globally declared.

+4
source share
3 answers

Very simple:

 UIFont *Boldfont = [UIFont boldSystemFontOfSize:16.0f]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:Boldfont forKey:UITextAttributeFont]; [segment setTitleTextAttributes:attributes forState:UIControlStateNormal]; 
+12
source

Consider redesigning your interface or use the tab style with a smaller font. If you use broken properties, your application may reject or terminate your application if it changes anything under the hood.

For example, the above code example does not work. When you click on a segment, the font for that segment gets reset to its normal size. Everything unpredictable can happen or change your application if you do something that deviates from the normal use of these things. Therefore, if you want an application that will continue to work in future OS updates to stick to standard material or create your own controls using UIButtons and rectangular background images. Now hacking can work, but it cannot be said that this will happen in the future.

+3
source

All Articles