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..
Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color. Select Default and then select Yes to apply the change to all new documents based on the template.
tintColor = [UIColor redColor]; for (id segment in [button subviews]) { for (id label in [segment subviews]) { if ([label isKindOfClass:[UILabel class]]) { UILabel *titleLabel = (UILabel *) label; [titleLabel setTextColor:[UIColor blackColor]]; } } } UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] ...
To change the overall color of the segmented control use its backgroundColor . To change the color of the selected segment use selectedSegmentTintColor . To change the color/font of the unselected segment titles, use setTitleTextAttributes with a state of . normal / UIControlStateNormal .
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
If you need to change the text color of the highlighted segment in iOS 7, here is a solution (took me awhile to find, but thanks to this post):
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorBlack]} forState:UIControlStateSelected];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With