From d58dfe7c7b2aad5a49a7cbfbb5896fa467fd050b Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Mon, 18 Nov 2013 19:08:51 -0800 Subject: [PATCH] remove button category. implement iOS 7 send button, first draft. update docs and demo. --- JSMessagesDemo.xcodeproj/project.pbxproj | 8 -- JSMessagesDemo/JSDemoViewController.m | 7 +- .../Categories/UIButton+JSMessagesView.h | 21 ----- .../Categories/UIButton+JSMessagesView.m | 49 ----------- .../Classes/JSMessageInputView.h | 12 ++- .../Classes/JSMessageInputView.m | 88 ++++++++++++++++--- .../Classes/JSMessagesViewController.m | 19 ++-- 7 files changed, 93 insertions(+), 111 deletions(-) delete mode 100644 JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.h delete mode 100644 JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.m diff --git a/JSMessagesDemo.xcodeproj/project.pbxproj b/JSMessagesDemo.xcodeproj/project.pbxproj index 0696826..e824a7e 100644 --- a/JSMessagesDemo.xcodeproj/project.pbxproj +++ b/JSMessagesDemo.xcodeproj/project.pbxproj @@ -23,8 +23,6 @@ 88A3FB82182E0B1700705327 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88A3FB81182E0B1700705327 /* AudioToolbox.framework */; }; 88A3FC59182E0EA000705327 /* NSString+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC1D182E0EA000705327 /* NSString+JSMessagesView.m */; }; 88A3FC5A182E0EA000705327 /* NSString+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC1D182E0EA000705327 /* NSString+JSMessagesView.m */; }; - 88A3FC5B182E0EA000705327 /* UIButton+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC1F182E0EA000705327 /* UIButton+JSMessagesView.m */; }; - 88A3FC5C182E0EA000705327 /* UIButton+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC1F182E0EA000705327 /* UIButton+JSMessagesView.m */; }; 88A3FC5D182E0EA000705327 /* UIColor+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC21182E0EA000705327 /* UIColor+JSMessagesView.m */; }; 88A3FC5E182E0EA000705327 /* UIColor+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC21182E0EA000705327 /* UIColor+JSMessagesView.m */; }; 88A3FC61182E0EA000705327 /* UIImage+JSMessagesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 88A3FC25182E0EA000705327 /* UIImage+JSMessagesView.m */; }; @@ -142,8 +140,6 @@ 88A3FC15182E0B8C00705327 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = ""; }; 88A3FC1C182E0EA000705327 /* NSString+JSMessagesView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+JSMessagesView.h"; sourceTree = ""; }; 88A3FC1D182E0EA000705327 /* NSString+JSMessagesView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+JSMessagesView.m"; sourceTree = ""; }; - 88A3FC1E182E0EA000705327 /* UIButton+JSMessagesView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIButton+JSMessagesView.h"; sourceTree = ""; }; - 88A3FC1F182E0EA000705327 /* UIButton+JSMessagesView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIButton+JSMessagesView.m"; sourceTree = ""; }; 88A3FC20182E0EA000705327 /* UIColor+JSMessagesView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+JSMessagesView.h"; sourceTree = ""; }; 88A3FC21182E0EA000705327 /* UIColor+JSMessagesView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+JSMessagesView.m"; sourceTree = ""; }; 88A3FC24182E0EA000705327 /* UIImage+JSMessagesView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+JSMessagesView.h"; sourceTree = ""; }; @@ -351,8 +347,6 @@ children = ( 88A3FC1C182E0EA000705327 /* NSString+JSMessagesView.h */, 88A3FC1D182E0EA000705327 /* NSString+JSMessagesView.m */, - 88A3FC1E182E0EA000705327 /* UIButton+JSMessagesView.h */, - 88A3FC1F182E0EA000705327 /* UIButton+JSMessagesView.m */, 88A3FC20182E0EA000705327 /* UIColor+JSMessagesView.h */, 88A3FC21182E0EA000705327 /* UIColor+JSMessagesView.m */, 88A3FC24182E0EA000705327 /* UIImage+JSMessagesView.h */, @@ -656,7 +650,6 @@ 88A3FB5A182E079E00705327 /* JSAppDelegate.m in Sources */, 88A3FC65182E0EA000705327 /* JSBubbleImageViewFactory.m in Sources */, 88A3FC59182E0EA000705327 /* NSString+JSMessagesView.m in Sources */, - 88A3FC5B182E0EA000705327 /* UIButton+JSMessagesView.m in Sources */, 88A3FC61182E0EA000705327 /* UIImage+JSMessagesView.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -665,7 +658,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 88A3FC5C182E0EA000705327 /* UIButton+JSMessagesView.m in Sources */, 88A3FC68182E0EA000705327 /* JSBubbleMessageCell.m in Sources */, 88A3FB78182E079E00705327 /* JSMessagesDemoTests.m in Sources */, 88A3FC5A182E0EA000705327 /* NSString+JSMessagesView.m in Sources */, diff --git a/JSMessagesDemo/JSDemoViewController.m b/JSMessagesDemo/JSDemoViewController.m index 799e9b1..f42261c 100644 --- a/JSMessagesDemo/JSDemoViewController.m +++ b/JSMessagesDemo/JSDemoViewController.m @@ -14,7 +14,6 @@ #import "JSDemoViewController.h" -#import "UIButton+JSMessagesView.h" #import "JSAvatarImageFactory.h" #define kSubtitleJobs @"Jobs" @@ -158,10 +157,8 @@ // // The button's frame is set automatically for you // -- (UIButton *)sendButtonForInputView -{ - return [UIButton js_defaultSendButton_iOS6]; -} +// - (UIButton *)sendButtonForInputView +// // *** Implement to prevent auto-scrolling when message is added // diff --git a/JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.h b/JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.h deleted file mode 100644 index 3b7ff2e..0000000 --- a/JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.h +++ /dev/null @@ -1,21 +0,0 @@ -// -// Created by Jesse Squires -// http://www.hexedbits.com -// -// -// Documentation -// http://cocoadocs.org/docsets/JSMessagesViewController -// -// -// The MIT License -// Copyright (c) 2013 Jesse Squires -// http://opensource.org/licenses/MIT -// - -#import - -@interface UIButton (JSMessagesView) - -+ (UIButton *)js_defaultSendButton_iOS6; - -@end \ No newline at end of file diff --git a/JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.m b/JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.m deleted file mode 100644 index 7f0aa56..0000000 --- a/JSMessagesViewController/Classes/Categories/UIButton+JSMessagesView.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// Created by Jesse Squires -// http://www.hexedbits.com -// -// -// Documentation -// http://cocoadocs.org/docsets/JSMessagesViewController -// -// -// The MIT License -// Copyright (c) 2013 Jesse Squires -// http://opensource.org/licenses/MIT -// - -#import "UIButton+JSMessagesView.h" - -@implementation UIButton (JSMessagesView) - -+ (UIButton *)js_defaultSendButton_iOS6 -{ - UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeCustom]; - sendButton.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin); - - UIEdgeInsets insets = UIEdgeInsetsMake(0.0f, 13.0f, 0.0f, 13.0f); - UIImage *sendBack = [[UIImage imageNamed:@"send-button"] resizableImageWithCapInsets:insets]; - UIImage *sendBackHighLighted = [[UIImage imageNamed:@"send-button-pressed"] resizableImageWithCapInsets:insets]; - [sendButton setBackgroundImage:sendBack forState:UIControlStateNormal]; - [sendButton setBackgroundImage:sendBack forState:UIControlStateDisabled]; - [sendButton setBackgroundImage:sendBackHighLighted forState:UIControlStateHighlighted]; - - NSString *title = NSLocalizedString(@"Send", nil); - [sendButton setTitle:title forState:UIControlStateNormal]; - [sendButton setTitle:title forState:UIControlStateHighlighted]; - [sendButton setTitle:title forState:UIControlStateDisabled]; - sendButton.titleLabel.font = [UIFont boldSystemFontOfSize:16.0f]; - - UIColor *titleShadow = [UIColor colorWithRed:0.325f green:0.463f blue:0.675f alpha:1.0f]; - [sendButton setTitleShadowColor:titleShadow forState:UIControlStateNormal]; - [sendButton setTitleShadowColor:titleShadow forState:UIControlStateHighlighted]; - sendButton.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f); - - [sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; - [sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; - [sendButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.5f] forState:UIControlStateDisabled]; - - return sendButton; -} - -@end \ No newline at end of file diff --git a/JSMessagesViewController/Classes/JSMessageInputView.h b/JSMessagesViewController/Classes/JSMessageInputView.h index b67e2bd..d4880c4 100644 --- a/JSMessagesViewController/Classes/JSMessageInputView.h +++ b/JSMessagesViewController/Classes/JSMessageInputView.h @@ -35,13 +35,20 @@ typedef NS_ENUM(NSUInteger, JSMessageInputViewStyle) { */ @interface JSMessageInputView : UIImageView +/** + * Returns the style appearance for the input view. + * @see JSMessageInputViewStyle. + */ +@property (assign, nonatomic, readonly) JSMessageInputViewStyle style; + /** * Returns the textView into which a new message is composed. This property is never `nil`. */ @property (weak, nonatomic, readonly) JSMessageTextView *textView; /** - * The send button for the input view. The default value is `nil`. + * The send button for the input view. The default value is an initialized `UIButton` whose appearance is styled according to the value of style during initialization. + @see JSMessageInputViewStyle. */ @property (weak, nonatomic) UIButton *sendButton; @@ -52,7 +59,8 @@ typedef NS_ENUM(NSUInteger, JSMessageInputViewStyle) { * * @param frame A rectangle specifying the initial location and size of the bubble view in its superview's coordinates. * @param style The style of the input view. @see JSMessageInputViewStyle. - * @param delegate An object that conforms to the `UITextViewDelegate` protocol and `JSDismissiveTextViewDelegate` protocol. @see JSDismissiveTextViewDelegate. + * @param delegate An object that conforms to the `UITextViewDelegate` protocol and `JSDismissiveTextViewDelegate` protocol. + * @see JSDismissiveTextViewDelegate. * @param panGestureRecognizer A `UIPanGestureRecognizer` used to dismiss the input view by dragging down. * * @return An initialized `JSMessageInputView` object or `nil` if the object could not be successfully initialized. diff --git a/JSMessagesViewController/Classes/JSMessageInputView.m b/JSMessagesViewController/Classes/JSMessageInputView.m index 710942f..7b35a2c 100644 --- a/JSMessagesViewController/Classes/JSMessageInputView.m +++ b/JSMessagesViewController/Classes/JSMessageInputView.m @@ -21,7 +21,8 @@ @interface JSMessageInputView () - (void)setup; -- (void)configureWithStyle:(JSMessageInputViewStyle)style; +- (void)configureInputBarWithStyle:(JSMessageInputViewStyle)style; +- (void)configureSendButtonWithStyle:(JSMessageInputViewStyle)style; @end @@ -39,7 +40,7 @@ self.userInteractionEnabled = YES; } -- (void)configureWithStyle:(JSMessageInputViewStyle)style +- (void)configureInputBarWithStyle:(JSMessageInputViewStyle)style { CGFloat width = self.frame.size.width - SEND_BUTTON_WIDTH; CGFloat height = [JSMessageInputView textViewLineHeight]; @@ -48,17 +49,7 @@ [self addSubview:textView]; _textView = textView; - if(style == JSMessageInputViewStyleFlat) { - _textView.frame = CGRectMake(4.0f, 4.5f, width, height); - _textView.backgroundColor = [UIColor clearColor]; - _textView.layer.borderColor = [UIColor colorWithWhite:0.8f alpha:1.0f].CGColor; - _textView.layer.borderWidth = 0.65f; - _textView.layer.cornerRadius = 6.0f; - - self.image = [[UIImage imageNamed:@"input-bar-flat"] resizableImageWithCapInsets:UIEdgeInsetsZero - resizingMode:UIImageResizingModeStretch]; - } - else if(style == JSMessageInputViewStyleClassic) { + if(style == JSMessageInputViewStyleClassic) { _textView.frame = CGRectMake(6.0f, 3.0f, width, height); _textView.backgroundColor = [UIColor whiteColor]; @@ -74,6 +65,61 @@ inputFieldBack.backgroundColor = [UIColor clearColor]; [self addSubview:inputFieldBack]; } + else { + _textView.frame = CGRectMake(4.0f, 4.5f, width, height); + _textView.backgroundColor = [UIColor clearColor]; + _textView.layer.borderColor = [UIColor colorWithWhite:0.8f alpha:1.0f].CGColor; + _textView.layer.borderWidth = 0.65f; + _textView.layer.cornerRadius = 6.0f; + + self.image = [[UIImage imageNamed:@"input-bar-flat"] resizableImageWithCapInsets:UIEdgeInsetsMake(2.0f, 0.0f, 0.0f, 0.0f) + resizingMode:UIImageResizingModeStretch]; + } +} + +- (void)configureSendButtonWithStyle:(JSMessageInputViewStyle)style +{ + UIButton *sendButton; + + if(style == JSMessageInputViewStyleClassic) { + UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeCustom]; + sendButton.autoresizingMask = (UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin); + + UIEdgeInsets insets = UIEdgeInsetsMake(0.0f, 13.0f, 0.0f, 13.0f); + UIImage *sendBack = [[UIImage imageNamed:@"send-button"] resizableImageWithCapInsets:insets]; + UIImage *sendBackHighLighted = [[UIImage imageNamed:@"send-button-pressed"] resizableImageWithCapInsets:insets]; + [sendButton setBackgroundImage:sendBack forState:UIControlStateNormal]; + [sendButton setBackgroundImage:sendBack forState:UIControlStateDisabled]; + [sendButton setBackgroundImage:sendBackHighLighted forState:UIControlStateHighlighted]; + + UIColor *titleShadow = [UIColor colorWithRed:0.325f green:0.463f blue:0.675f alpha:1.0f]; + [sendButton setTitleShadowColor:titleShadow forState:UIControlStateNormal]; + [sendButton setTitleShadowColor:titleShadow forState:UIControlStateHighlighted]; + sendButton.titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f); + + [sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; + [sendButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted]; + [sendButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.5f] forState:UIControlStateDisabled]; + + sendButton.titleLabel.font = [UIFont boldSystemFontOfSize:16.0f]; + } + else { + sendButton = [UIButton buttonWithType:UIButtonTypeCustom]; + sendButton.backgroundColor = [UIColor clearColor]; + + [sendButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; + [sendButton setTitleColor:[UIColor blueColor] forState:UIControlStateHighlighted]; + [sendButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateDisabled]; + + sendButton.titleLabel.font = [UIFont boldSystemFontOfSize:18.0f]; + } + + NSString *title = NSLocalizedString(@"Send", nil); + [sendButton setTitle:title forState:UIControlStateNormal]; + [sendButton setTitle:title forState:UIControlStateHighlighted]; + [sendButton setTitle:title forState:UIControlStateDisabled]; + + [self setSendButton:sendButton]; } - (instancetype)initWithFrame:(CGRect)frame @@ -83,8 +129,11 @@ { self = [super initWithFrame:frame]; if(self) { + _style = style; [self setup]; - [self configureWithStyle:style]; + [self configureInputBarWithStyle:style]; + [self configureSendButtonWithStyle:style]; + _textView.delegate = delegate; _textView.keyboardDelegate = delegate; _textView.dismissivePanGestureRecognizer = panGestureRecognizer; @@ -113,6 +162,17 @@ if(_sendButton) [_sendButton removeFromSuperview]; + if(self.style == JSMessageInputViewStyleClassic) { + btn.frame = CGRectMake(self.frame.size.width - 65.0f, 8.0f, 59.0f, 26.0f); + } + else { + CGFloat padding = 8.0f; + btn.frame = CGRectMake(self.textView.frame.origin.x + self.textView.frame.size.width + padding, + padding, + 60.0f, + self.textView.frame.size.height - padding); + } + [self addSubview:btn]; _sendButton = btn; } diff --git a/JSMessagesViewController/Classes/JSMessagesViewController.m b/JSMessagesViewController/Classes/JSMessagesViewController.m index c33cb26..be8cba2 100644 --- a/JSMessagesViewController/Classes/JSMessagesViewController.m +++ b/JSMessagesViewController/Classes/JSMessagesViewController.m @@ -17,7 +17,6 @@ #import "NSString+JSMessagesView.h" #import "UIColor+JSMessagesView.h" -#import "UIButton+JSMessagesView.h" @interface JSMessagesViewController () @@ -85,19 +84,15 @@ delegate:self panGestureRecognizer:_tableView.panGestureRecognizer]; - UIButton *sendButton; if([self.delegate respondsToSelector:@selector(sendButtonForInputView)]) { - sendButton = [self.delegate sendButtonForInputView]; + UIButton *sendButton = [self.delegate sendButtonForInputView]; + [inputView setSendButton:sendButton]; } - else { - sendButton = [UIButton js_defaultSendButton_iOS6]; - } - sendButton.enabled = NO; - sendButton.frame = CGRectMake(inputView.frame.size.width - 65.0f, 8.0f, 59.0f, 26.0f); - [sendButton addTarget:self - action:@selector(sendPressed:) - forControlEvents:UIControlEventTouchUpInside]; - [inputView setSendButton:sendButton]; + + inputView.sendButton.enabled = NO; + [inputView.sendButton addTarget:self + action:@selector(sendPressed:) + forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:inputView]; _messageInputView = inputView;