I try to change font color from white to black for UISegmentedControl (for iOS 4.*)
UISegmentedControl *button = [[[UISegmentedControl alloc] in
Just in case to help someone else that get there and is working using swift.
I will put the two possible ways of doing it. You can change the text attributes in the UIAppearance or directly in the segmented your are working.
The first example setting the attributes in the appearance, this way you will customize all the segmented controls in your app:
let attributes = [ NSForegroundColorAttributeName : UIColor.grayColor(),
NSFontAttributeName : UIFont.systemFontOfSize(20)];
let attributesSelected = [ NSForegroundColorAttributeName : UIColor.blueColor(),
NSFontAttributeName : UIFont.systemFontOfSize(20)];
UISegmentedControl.appearance().setTitleTextAttributes(attributes, forState: UIControlState.Normal)
UISegmentedControl.appearance().setTitleTextAttributes(attributesSelected, forState: UIControlState.Selected)
The second example, directly in the segmented, will customize only this segmented:
let attributes = [ NSForegroundColorAttributeName : UIColor.grayColor(),
NSFontAttributeName : UIFont.systemFontOfSize(20)];
let attributesSelected = [ NSForegroundColorAttributeName : UIColor.blueColor(),
NSFontAttributeName : UIFont.systemFontOfSize(20)];
segmented.setTitleTextAttributes(attributes, forState: UIControlState.Normal)
segmented.setTitleTextAttributes(attributesSelected, forState: UIControlState.Selected)