Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added backspace button

  • Loading branch information...
commit 236d4014564855af959af52b1c403a9532d02af9 1 parent 39d189c
John Britton authored
14 calculator/calculator/CalculatorViewController.m
View
@@ -60,6 +60,20 @@ - (IBAction)clearPressed {
self.userIsEnteringDigitsAfterDecimalPoint = NO;
}
+- (IBAction)backspacePressed {
+ if (self.userIsInTheMiddleOfEnteringANumber) {
+ int displayLength = [self.display.text length];
+ if (displayLength > 1) {
+ NSRange range = {0, displayLength-1};
+ self.display.text = [self.display.text substringWithRange:range];
+ } else if (displayLength == 1) {
+ self.display.text = @"0";
+ self.userIsInTheMiddleOfEnteringANumber = NO;
+ }
+ }
+
+}
+
- (IBAction)operationPressed:(UIButton *)sender {
if (self.userIsInTheMiddleOfEnteringANumber) {
[self enterPressed];
17 calculator/calculator/en.lproj/MainStoryboard.storyboard
View
@@ -15,7 +15,7 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="10" id="ZUI-1k-70Q">
- <rect key="frame" x="92" y="20" width="208" height="42"/>
+ <rect key="frame" x="92" y="20" width="136" height="42"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" name="Courier" family="Courier" pointSize="35"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
@@ -343,6 +343,21 @@
<action selector="clearPressed" destination="2" eventType="touchUpInside" id="N52-Jx-fIQ"/>
</connections>
</button>
+ <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="mcM-PN-SHf">
+ <rect key="frame" x="236" y="25" width="64" height="37"/>
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+ <fontDescription key="fontDescription" type="boldSystem" pointSize="15"/>
+ <state key="normal" title="←">
+ <color key="titleColor" red="0.19607843459999999" green="0.30980393290000002" blue="0.52156865600000002" alpha="1" colorSpace="calibratedRGB"/>
+ <color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
+ </state>
+ <state key="highlighted">
+ <color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+ </state>
+ <connections>
+ <action selector="backspacePressed" destination="2" eventType="touchUpInside" id="LcU-Mh-lHL"/>
+ </connections>
+ </button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
Please sign in to comment.
Something went wrong with that request. Please try again.