Skip to content

Commit 0c9aa6a

Browse files
Bit o'code cleanup
1 parent ff3dced commit 0c9aa6a

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

DNSCastroSegmentedControl/Base.lproj/Main.storyboard

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6250" systemVersion="14A389" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6254" systemVersion="14B25" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="vXZ-lx-hvc">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
55
</dependencies>
66
<scenes>
77
<!--View Controller-->
@@ -17,21 +17,21 @@
1717
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1818
<subviews>
1919
<view contentMode="scaleToFill" placeholderIntrinsicWidth="infinite" placeholderIntrinsicHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="ovI-wb-jw2" customClass="DNSCastroSegmentedControl">
20-
<rect key="frame" x="40" y="88" width="240" height="40"/>
20+
<rect key="frame" x="40" y="108" width="240" height="40"/>
2121
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
2222
<connections>
23-
<action selector="DNSCastroSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="SlJ-uE-ST3"/>
23+
<action selector="customSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="WGq-so-waS"/>
2424
</connections>
2525
</view>
2626
<view contentMode="scaleToFill" placeholderIntrinsicWidth="infinite" placeholderIntrinsicHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="XHm-9W-22v" customClass="DNSCastroSegmentedControl">
27-
<rect key="frame" x="40" y="168" width="240" height="40"/>
27+
<rect key="frame" x="40" y="188" width="240" height="40"/>
2828
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
2929
<connections>
30-
<action selector="DNSCastroSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="hWS-qZ-oIb"/>
30+
<action selector="customSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="126-5H-fcp"/>
3131
</connections>
3232
</view>
3333
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="27t-dN-biq">
34-
<rect key="frame" x="99" y="20" width="123" height="29"/>
34+
<rect key="frame" x="99" y="40" width="123" height="29"/>
3535
<segments>
3636
<segment title="First"/>
3737
<segment title="Second"/>
@@ -46,7 +46,7 @@
4646
<constraint firstAttribute="trailing" secondItem="XHm-9W-22v" secondAttribute="trailing" constant="40" id="4le-Ud-K0s"/>
4747
<constraint firstAttribute="trailing" secondItem="ovI-wb-jw2" secondAttribute="trailing" constant="40" id="9Wu-6r-EUg"/>
4848
<constraint firstItem="ovI-wb-jw2" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="40" id="Ks2-ZK-gsx"/>
49-
<constraint firstItem="27t-dN-biq" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" id="aLq-dN-WFv"/>
49+
<constraint firstItem="27t-dN-biq" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="20" id="aLq-dN-WFv"/>
5050
<constraint firstItem="XHm-9W-22v" firstAttribute="top" secondItem="ovI-wb-jw2" secondAttribute="bottom" constant="40" id="f3C-fx-OzS"/>
5151
<constraint firstItem="ovI-wb-jw2" firstAttribute="top" secondItem="27t-dN-biq" secondAttribute="bottom" constant="40" id="hZ5-LF-bmt"/>
5252
<constraint firstItem="XHm-9W-22v" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="40" id="izC-OW-Q5Y"/>
@@ -56,11 +56,12 @@
5656
<connections>
5757
<outlet property="segmentedControl" destination="ovI-wb-jw2" id="SlU-vZ-SMX"/>
5858
<outlet property="stairsSegmentedControl" destination="XHm-9W-22v" id="bHJ-hG-Enq"/>
59+
<outlet property="standardSegmentedControl" destination="27t-dN-biq" id="215-Vk-YsG"/>
5960
</connections>
6061
</viewController>
6162
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
6263
</objects>
63-
<point key="canvasLocation" x="596" y="162"/>
64+
<point key="canvasLocation" x="416" y="145"/>
6465
</scene>
6566
</scenes>
6667
<simulatedMetricsContainer key="defaultSimulatedMetrics">

DNSCastroSegmentedControl/ViewController.m

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
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

Comments
 (0)