How to configure UISegmentedControl in iOS?

I am setting up a UISegmentedControl, but I am having a problem.

How to apply background image in UISegmentedControl? Changing the color of the shade does not meet my requirements.

thanks

+6
source share
2 answers
////Segmented Controll NSArray *segmentTextContent = [NSArray arrayWithObjects: @"First",@"Second",@"Third",@"Forth", nil]; segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent]; segmentedControl.frame = CGRectMake(2, 5, 316, 35); [segmentedControl addTarget:self action:@selector(segmentAction) forControlEvents:UIControlEventValueChanged]; segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; segmentedControl.enabled = true; segmentedControl.selectedSegmentIndex = 0; // cutomize the font size inside segmentedControl for (id segment in [segmentedControl subviews]) { for (id label in [segment subviews]) { if ([label isKindOfClass:[UILabel class]]) { [label setTextAlignment:UITextAlignmentCenter]; [label setFont:[UIFont boldSystemFontOfSize:11]]; //[label setTextColor:[UIColor greenColor]]; } } } 
+5
source

Source: https://habr.com/ru/post/895226/


All Articles