1111#import " DNSCastroSegmentedControl.h"
1212
1313@interface ViewController ()
14+ @property (nonatomic , weak ) IBOutlet UISegmentedControl *standardSegmentedControl;
1415@property (nonatomic , weak ) IBOutlet DNSCastroSegmentedControl *segmentedControl;
1516@property (nonatomic , weak ) IBOutlet DNSCastroSegmentedControl *stairsSegmentedControl;
1617@property (nonatomic ) DNSCastroSegmentedControl *programmaticSegmentedControl;
@@ -21,9 +22,17 @@ @implementation ViewController
2122- (void )viewDidLoad
2223{
2324 [super viewDidLoad ];
24- // Do any additional setup after loading the view, typically from a nib.
2525
26- self.segmentedControl .choices = @[@" one" , @" two" , @" three" , @" four" ];
26+ // Make the standard segmented control more visible on the black bg.
27+ self.standardSegmentedControl .tintColor = [UIColor whiteColor ];
28+
29+ // Setup the choices for the IBOutlet segmented controls.
30+ self.segmentedControl .choices = @[
31+ @" one" ,
32+ @" two" ,
33+ @" three" ,
34+ @" four" ,
35+ ];
2736 self.segmentedControl .labelFont = [UIFont fontWithName: @" AmericanTypewriter" size: 17 ];
2837 self.segmentedControl .selectedSegmentIndex = 2 ;
2938 self.segmentedControl .tintColor = [UIColor orangeColor ];
@@ -69,6 +78,7 @@ - (void)viewDidLayoutSubviews
6978 attribute: NSLayoutAttributeLeft
7079 multiplier: 1
7180 constant: 0 ]];
81+
7282 [self .view addConstraint: [NSLayoutConstraint constraintWithItem: self .programmaticSegmentedControl
7383 attribute: NSLayoutAttributeRight
7484 relatedBy: NSLayoutRelationEqual
@@ -77,14 +87,15 @@ - (void)viewDidLayoutSubviews
7787 multiplier: 1
7888 constant: 0 ]];
7989
80- // NOTE: Height does not need to be pinned due to intrinsic content size.
81-
90+ // NOTE: Height does not need to be pinned due to intrinsic content size.
8291 self.programmaticSegmentedControl .choices = @[@" Programmatic" , @" Springs/Struts" , @" Autolayout" ];
8392 self.programmaticSegmentedControl .labelFont = [UIFont fontWithName: @" AppleSDGothicNeo-Medium" size: 14 ];
8493 self.programmaticSegmentedControl .choiceColor = [UIColor orangeColor ];
8594 self.programmaticSegmentedControl .selectedSegmentIndex = 1 ;
8695
87- [self .programmaticSegmentedControl addTarget: self action: @selector (DNSCastroSegmentedControlChanged: ) forControlEvents: UIControlEventValueChanged];
96+ [self .programmaticSegmentedControl addTarget: self
97+ action: @selector (customSegmentedControlChanged: )
98+ forControlEvents: UIControlEventValueChanged];
8899
89100 // Uncomment to move automatically after a delay
90101// [self performSelector:@selector(setProgrammaticIndex)
@@ -98,11 +109,12 @@ - (void)setProgrammaticIndex
98109 [self .programmaticSegmentedControl setSelectedSegmentIndex: 2 animated: YES ];
99110}
100111
101- - (IBAction )standardSegmentedControlChanged : (UISegmentedControl *)sender {
102- NSLog (@" %s Standard segmented control change to index %@ " ,__PRETTY_FUNCTION__,@(sender.selectedSegmentIndex ));
112+ - (IBAction )standardSegmentedControlChanged : (UISegmentedControl *)sender
113+ {
114+ NSLog (@" Standard segmented control changed to index %@ " , @(sender.selectedSegmentIndex ));
103115}
104116
105- - (IBAction )DNSCastroSegmentedControlChanged : (DNSCastroSegmentedControl *)sender
117+ - (IBAction )customSegmentedControlChanged : (DNSCastroSegmentedControl *)sender
106118{
107119 NSString *controlName = nil ;
108120 if (sender == self.segmentedControl ) {
@@ -113,7 +125,7 @@ - (IBAction)DNSCastroSegmentedControlChanged:(DNSCastroSegmentedControl *)sender
113125 controlName = @" Programmatic Segmented Control" ;
114126 }
115127
116- NSLog (@" Control %@ change to index %@ " , controlName, @(sender.selectedSegmentIndex ));
128+ NSLog (@" Control %@ changed to index %@ " , controlName, @(sender.selectedSegmentIndex ));
117129}
118130
119131@end
0 commit comments