diff --git a/JCDialPad/JCDialPad.h b/JCDialPad/JCDialPad.h index 2ffaa23..1b1ec9e 100755 --- a/JCDialPad/JCDialPad.h +++ b/JCDialPad/JCDialPad.h @@ -6,6 +6,7 @@ @optional - (BOOL)dialPad:(JCDialPad *)dialPad shouldInsertText:(NSString *)text forButtonPress:(JCPadButton *)button; - (BOOL)dialPad:(JCDialPad *)dialPad shouldInsertText:(NSString *)text forLongButtonPress:(JCPadButton *)button; +- (void)dialPad:(JCDialPad *)dialPad didChanged:(NSString *)rawText; @end @@ -24,6 +25,8 @@ @property (nonatomic, strong) UIButton *deleteButton; @property (nonatomic, strong) UITextField *digitsTextField; +@property (nonatomic, strong) NSString *recipient; + @property (weak, nonatomic) id delegate; /** diff --git a/JCDialPad/JCDialPad.m b/JCDialPad/JCDialPad.m index a3a4e8a..85b12fd 100755 --- a/JCDialPad/JCDialPad.m +++ b/JCDialPad/JCDialPad.m @@ -15,6 +15,7 @@ @interface JCDialPad() @property (nonatomic, strong) UIView* contentView; @property (nonatomic, strong) UIView* backgroundBlurringView; @property (nonatomic, strong) NBAsYouTypeFormatter *numFormatter; +@property (nonatomic, strong) UILabel *recipientLabel; @end @@ -78,8 +79,14 @@ - (void)initializeProperties self.digitsTextField.textColor = [self.mainColor colorWithAlphaComponent:0.9]; self.formatTextToPhoneNumber = YES; - self.regionCode = @"US"; self.rawText = @""; + + self.recipientLabel = [[UILabel alloc] init]; + self.recipientLabel.textAlignment = NSTextAlignmentCenter; + self.recipientLabel.backgroundColor = [UIColor clearColor]; + self.recipientLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:11.0]; + self.recipientLabel.textColor = [self.mainColor colorWithAlphaComponent:0.9]; + self.recipientLabel.alpha = 0.0f; } #pragma mark - @@ -156,6 +163,18 @@ - (void)setBackgroundView:(UIView *)backgroundView } } +- (void)setRecipient:(NSString *)recipient +{ + [UIView animateWithDuration:0.2f animations:^{ + self.recipientLabel.alpha = 0.0f; + } completion:^(BOOL finished) { + self.recipientLabel.text = recipient; + [UIView animateWithDuration:0.2f animations:^{ + self.recipientLabel.alpha = 1.0f; + }]; + }]; +} + #pragma mark - Helper Methods - (void)didTapButton:(UIButton *)sender { @@ -215,13 +234,21 @@ - (void)appendText:(NSString *)text self.digitsTextField.text = formatted; [self toggleDeleteButtonVisible:YES animated:YES]; + + if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) { + [_delegate dialPad:self didChanged:_rawText]; + } } } - (void)didTapDeleteButton:(UIButton *)sender { - if (!self.rawText.length) + if (!self.rawText.length) { + if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) { + [_delegate dialPad:self didChanged:_rawText]; + } return; + } _rawText = [self.rawText substringToIndex:self.rawText.length - 1]; NSString *formatted = self.rawText; @@ -233,11 +260,17 @@ - (void)didTapDeleteButton:(UIButton *)sender if (!self.rawText.length) { [self toggleDeleteButtonVisible:NO animated:YES]; } + if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) { + [_delegate dialPad:self didChanged:_rawText]; + } } - (void)didHoldDeleteButton:(UIGestureRecognizer *)holdRec { self.rawText = @""; + if ([self.delegate respondsToSelector:@selector(dialPad:didChanged:)] == YES) { + [_delegate dialPad:self didChanged:_rawText]; + } } #pragma mark - Layout Methods @@ -266,6 +299,9 @@ - (void)layoutTitleArea self.deleteButton.frame = CGRectMake(self.digitsTextField.right + 2, self.digitsTextField.center.y - 10, top + 28, 20); [self.contentView addSubview:self.deleteButton]; + + self.recipientLabel.frame = CGRectMake(self.digitsTextField.x, self.digitsTextField.bottom, self.digitsTextField.width, 10.0f); + [self.contentView addSubview:self.recipientLabel]; } - (void)layoutButtons diff --git a/JCDialPadDemo/JCDialPadDemo.xcodeproj/project.pbxproj b/JCDialPadDemo/JCDialPadDemo.xcodeproj/project.pbxproj index 8d8cfe9..9d47fd4 100755 --- a/JCDialPadDemo/JCDialPadDemo.xcodeproj/project.pbxproj +++ b/JCDialPadDemo/JCDialPadDemo.xcodeproj/project.pbxproj @@ -35,6 +35,8 @@ /* Begin PBXFileReference section */ 22C029B1E7A346D2ADBE703D /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 295EA24F3F21109D11BD04E4 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; + 5C701019DB74FB49ED98DA43 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; 86F9242A1936B772007C3772 /* JCDialPadDemoAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JCDialPadDemoAppDelegate.h; path = "JCDialPadDemo/Application Bootstrap/JCDialPadDemoAppDelegate.h"; sourceTree = SOURCE_ROOT; }; 86F9242B1936B772007C3772 /* JCDialPadDemoAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = JCDialPadDemoAppDelegate.m; path = "JCDialPadDemo/Application Bootstrap/JCDialPadDemoAppDelegate.m"; sourceTree = SOURCE_ROOT; }; 86F9242D1936B7A6007C3772 /* ExampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ExampleViewController.h; path = "JCDialPadDemo/Your Modules/ExampleViewController.h"; sourceTree = SOURCE_ROOT; }; @@ -52,7 +54,6 @@ 9C79B0F0188A184A00D465D8 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 9C79B18A188A1A7100D465D8 /* JCDialPadDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JCDialPadDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 9C9F7AB5188A40A1004B0B6D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; - C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -89,7 +90,7 @@ 9C79B0DD188A184A00D465D8 /* JCDialPadDemo */, 9C79B0D6188A184A00D465D8 /* Frameworks */, 9C79B0D5188A184A00D465D8 /* Products */, - C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */, + D59200BEA0F8424C8E921E53 /* Pods */, ); sourceTree = ""; }; @@ -122,7 +123,6 @@ 9C79B109188A18A100D465D8 /* Your Modules */, 9C79B0DE188A184A00D465D8 /* Supporting Files */, ); - name = JCDialPadDemo; path = JCDialPadDemo; sourceTree = ""; }; @@ -155,6 +155,15 @@ path = "Your Modules"; sourceTree = ""; }; + D59200BEA0F8424C8E921E53 /* Pods */ = { + isa = PBXGroup; + children = ( + 295EA24F3F21109D11BD04E4 /* Pods.debug.xcconfig */, + 5C701019DB74FB49ED98DA43 /* Pods.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -276,7 +285,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -384,7 +393,7 @@ }; 9C79B101188A184A00D465D8 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */; + baseConfigurationReference = 295EA24F3F21109D11BD04E4 /* Pods.debug.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -400,7 +409,7 @@ }; 9C79B102188A184A00D465D8 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = C8B96AFF58F24F6EBCC5EB9A /* Pods.xcconfig */; + baseConfigurationReference = 5C701019DB74FB49ED98DA43 /* Pods.release.xcconfig */; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; diff --git a/JCDialPadDemo/JCDialPadDemo/Your Modules/ExampleViewController.m b/JCDialPadDemo/JCDialPadDemo/Your Modules/ExampleViewController.m index 36f52b0..f123862 100644 --- a/JCDialPadDemo/JCDialPadDemo/Your Modules/ExampleViewController.m +++ b/JCDialPadDemo/JCDialPadDemo/Your Modules/ExampleViewController.m @@ -19,6 +19,7 @@ - (void)viewDidLoad self.view.buttons = [[JCDialPad defaultButtons] arrayByAddingObjectsFromArray:@[self.twilioButton, self.callButton]]; self.view.delegate = self; + self.view.recipient = @"Press 000 see how it works"; UIImageView* backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"wallpaper"]]; backgroundView.contentMode = UIViewContentModeScaleAspectFill; @@ -67,6 +68,15 @@ - (BOOL)dialPad:(JCDialPad *)dialPad shouldInsertText:(NSString *)text forButton return YES; } +- (void)dialPad:(JCDialPad *)dialPad didChanged:(NSString *)rawText +{ + if ([rawText isEqualToString:@"000"] == YES) { + dialPad.recipient = @"Daniel KIM"; + } else { + dialPad.recipient = @""; + } +} + - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent;