Skip to content

Commit

Permalink
Bit o'code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
designatednerd committed Dec 5, 2014
1 parent ff3dced commit 0c9aa6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
19 changes: 10 additions & 9 deletions DNSCastroSegmentedControl/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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">
<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">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6244"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -17,21 +17,21 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" placeholderIntrinsicWidth="infinite" placeholderIntrinsicHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="ovI-wb-jw2" customClass="DNSCastroSegmentedControl">
<rect key="frame" x="40" y="88" width="240" height="40"/>
<rect key="frame" x="40" y="108" width="240" height="40"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<action selector="DNSCastroSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="SlJ-uE-ST3"/>
<action selector="customSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="WGq-so-waS"/>
</connections>
</view>
<view contentMode="scaleToFill" placeholderIntrinsicWidth="infinite" placeholderIntrinsicHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="XHm-9W-22v" customClass="DNSCastroSegmentedControl">
<rect key="frame" x="40" y="168" width="240" height="40"/>
<rect key="frame" x="40" y="188" width="240" height="40"/>
<color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<connections>
<action selector="DNSCastroSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="hWS-qZ-oIb"/>
<action selector="customSegmentedControlChanged:" destination="vXZ-lx-hvc" eventType="valueChanged" id="126-5H-fcp"/>
</connections>
</view>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="27t-dN-biq">
<rect key="frame" x="99" y="20" width="123" height="29"/>
<rect key="frame" x="99" y="40" width="123" height="29"/>
<segments>
<segment title="First"/>
<segment title="Second"/>
Expand All @@ -46,7 +46,7 @@
<constraint firstAttribute="trailing" secondItem="XHm-9W-22v" secondAttribute="trailing" constant="40" id="4le-Ud-K0s"/>
<constraint firstAttribute="trailing" secondItem="ovI-wb-jw2" secondAttribute="trailing" constant="40" id="9Wu-6r-EUg"/>
<constraint firstItem="ovI-wb-jw2" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="40" id="Ks2-ZK-gsx"/>
<constraint firstItem="27t-dN-biq" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" id="aLq-dN-WFv"/>
<constraint firstItem="27t-dN-biq" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="20" id="aLq-dN-WFv"/>
<constraint firstItem="XHm-9W-22v" firstAttribute="top" secondItem="ovI-wb-jw2" secondAttribute="bottom" constant="40" id="f3C-fx-OzS"/>
<constraint firstItem="ovI-wb-jw2" firstAttribute="top" secondItem="27t-dN-biq" secondAttribute="bottom" constant="40" id="hZ5-LF-bmt"/>
<constraint firstItem="XHm-9W-22v" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="40" id="izC-OW-Q5Y"/>
Expand All @@ -56,11 +56,12 @@
<connections>
<outlet property="segmentedControl" destination="ovI-wb-jw2" id="SlU-vZ-SMX"/>
<outlet property="stairsSegmentedControl" destination="XHm-9W-22v" id="bHJ-hG-Enq"/>
<outlet property="standardSegmentedControl" destination="27t-dN-biq" id="215-Vk-YsG"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="596" y="162"/>
<point key="canvasLocation" x="416" y="145"/>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
Expand Down
30 changes: 21 additions & 9 deletions DNSCastroSegmentedControl/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "DNSCastroSegmentedControl.h"

@interface ViewController ()
@property (nonatomic, weak) IBOutlet UISegmentedControl *standardSegmentedControl;
@property (nonatomic, weak) IBOutlet DNSCastroSegmentedControl *segmentedControl;
@property (nonatomic, weak) IBOutlet DNSCastroSegmentedControl *stairsSegmentedControl;
@property (nonatomic) DNSCastroSegmentedControl *programmaticSegmentedControl;
Expand All @@ -21,9 +22,17 @@ @implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.segmentedControl.choices = @[@"one", @"two", @"three", @"four"];
//Make the standard segmented control more visible on the black bg.
self.standardSegmentedControl.tintColor = [UIColor whiteColor];

//Setup the choices for the IBOutlet segmented controls.
self.segmentedControl.choices = @[
@"one",
@"two",
@"three",
@"four",
];
self.segmentedControl.labelFont = [UIFont fontWithName:@"AmericanTypewriter" size:17];
self.segmentedControl.selectedSegmentIndex = 2;
self.segmentedControl.tintColor = [UIColor orangeColor];
Expand Down Expand Up @@ -69,6 +78,7 @@ - (void)viewDidLayoutSubviews
attribute:NSLayoutAttributeLeft
multiplier:1
constant:0]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.programmaticSegmentedControl
attribute:NSLayoutAttributeRight
relatedBy:NSLayoutRelationEqual
Expand All @@ -77,14 +87,15 @@ - (void)viewDidLayoutSubviews
multiplier:1
constant:0]];

//NOTE: Height does not need to be pinned due to intrinsic content size.

//NOTE: Height does not need to be pinned due to intrinsic content size.
self.programmaticSegmentedControl.choices = @[@"Programmatic", @"Springs/Struts", @"Autolayout"];
self.programmaticSegmentedControl.labelFont = [UIFont fontWithName:@"AppleSDGothicNeo-Medium" size:14];
self.programmaticSegmentedControl.choiceColor = [UIColor orangeColor];
self.programmaticSegmentedControl.selectedSegmentIndex = 1;

[self.programmaticSegmentedControl addTarget:self action:@selector(DNSCastroSegmentedControlChanged:) forControlEvents:UIControlEventValueChanged];
[self.programmaticSegmentedControl addTarget:self
action:@selector(customSegmentedControlChanged:)
forControlEvents:UIControlEventValueChanged];

//Uncomment to move automatically after a delay
// [self performSelector:@selector(setProgrammaticIndex)
Expand All @@ -98,11 +109,12 @@ - (void)setProgrammaticIndex
[self.programmaticSegmentedControl setSelectedSegmentIndex:2 animated:YES];
}

- (IBAction)standardSegmentedControlChanged:(UISegmentedControl *)sender {
NSLog(@"%s Standard segmented control change to index %@",__PRETTY_FUNCTION__,@(sender.selectedSegmentIndex));
- (IBAction)standardSegmentedControlChanged:(UISegmentedControl *)sender
{
NSLog(@"Standard segmented control changed to index %@", @(sender.selectedSegmentIndex));
}

- (IBAction)DNSCastroSegmentedControlChanged:(DNSCastroSegmentedControl *)sender
- (IBAction)customSegmentedControlChanged:(DNSCastroSegmentedControl *)sender
{
NSString *controlName = nil;
if (sender == self.segmentedControl) {
Expand All @@ -113,7 +125,7 @@ - (IBAction)DNSCastroSegmentedControlChanged:(DNSCastroSegmentedControl *)sender
controlName = @"Programmatic Segmented Control";
}

NSLog(@"Control %@ change to index %@", controlName, @(sender.selectedSegmentIndex));
NSLog(@"Control %@ changed to index %@", controlName, @(sender.selectedSegmentIndex));
}

@end

0 comments on commit 0c9aa6a

Please sign in to comment.