Change text color of UISegmentedControl

objective-c, xcode

Solution

There's no way to set the custom color of selected segment title in `UISegmentedControl`. The `UIControlState` in `forState:` used to set the attributes of segment text for normal and selected state.

From Your Code :

[[UIsegmentControl.subviews objectAtIndex:segment.selectedSegmentIndex] setTintColor:[UIColor redColor]];

Try This Code:

[segmnt_cntrl setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"Arial" size:16.0],
                                                          NSForegroundColorAttributeName:[UIColor redColor],
                                                          NSShadowAttributeName:shadow}
                                                         forState:UIControlStateNormal];

Replace the segmnt_cntrl with your object of Segment Cotrol. Try this , It might helps you to achieve your over all goal.

Thanks

Problem

Iam new to objective c,need to change the text color of selected segment in UIsegmentControl. Used following code. ``` [[UIsegmentControl.subviews objectAtIndex:segment.selectedSegmentIndex] setTintColor:[UIColor redColor]]; ``` it changes segment color.Help me please..

Original source

Related problems