1

I want to change the font of UISegmentedControl without changing the font size.

This is my code but, obviously, in this case i change the font size too:

let attr = NSDictionary(object: UIFont(name: "Avenir", size: 12.0)!, forKey: NSFontAttributeName)
segmentedControl.setTitleTextAttributes(attr as [NSObject : AnyObject] , forState: .Normal)

How can I solve this?

Matteo Serpentoni
  • 553
  • 1
  • 7
  • 19

1 Answers1

0

Try following code, this is not proper way, but we don't have other option, then we should go via this wat

int fontSize;
for (id segment in [segmentedControl subviews]) 
{
    for (id label in [segment subviews]) 
    {
        if ([label isKindOfClass:[UILabel class]])
        {
          fontSize = label.font.pointSize;
          // Here you got the label, now use the font size from here
          break;
        }
    }   
}

Now you got the fontSize, now you can use this to change the font face

Mehul Thakkar
  • 12,440
  • 10
  • 52
  • 81