iAppDeveloper iAppDeveloper - 1 year ago 208
Objective-C Question

Change text color of UISegmentedControl

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..

Answer Source

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],

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


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