From bea1efd34f09e7eff15d03f7e6d3b1d44c967459 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 3 Oct 2019 16:35:31 +0300 Subject: Autoresizing MessageInput --- Juick/Views/MessageInputView.h | 9 ++++-- Juick/Views/MessageInputView.m | 20 +++++++++++-- Juick/Views/MessageInputView.xib | 63 +++++++++++++++++++++++++++------------- 3 files changed, 67 insertions(+), 25 deletions(-) diff --git a/Juick/Views/MessageInputView.h b/Juick/Views/MessageInputView.h index c78f498..9cf3652 100644 --- a/Juick/Views/MessageInputView.h +++ b/Juick/Views/MessageInputView.h @@ -14,9 +14,14 @@ @end -@interface MessageInputView : UIVisualEffectView +@interface MessageInputView : UIVisualEffectView @property (strong, nonatomic) IBOutlet NSLayoutConstraint *bottomConstraint; -@property (strong, nonatomic) IBOutlet UITextField *textView; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textHeightConstraint; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *topMarginConstraint; +@property (strong, nonatomic) IBOutlet UITextView *textView; + +@property (weak, nonatomic) IBOutlet UIButton *sendButton; + - (IBAction)sendPressed:(id)sender; @property (nonatomic, weak) id delegate; diff --git a/Juick/Views/MessageInputView.m b/Juick/Views/MessageInputView.m index c4d96de..054ded7 100644 --- a/Juick/Views/MessageInputView.m +++ b/Juick/Views/MessageInputView.m @@ -10,9 +10,23 @@ @implementation MessageInputView --(void) awakeFromNib { - [super awakeFromNib]; - [self setTintColor:[UIColor colorNamed:@"Title"]]; +- (CGSize) textSize { + CGSize size = CGSizeMake(self.textView.bounds.size.width, FLT_MAX); + return [self.textView sizeThatFits:size]; +} + +- (CGSize) intrinsicContentSize { + CGSize viewSize = [self textSize]; + viewSize.height = viewSize.height + self.bottomConstraint.constant + self.topMarginConstraint.constant; + return viewSize; +} + +- (void)textViewDidChange:(UITextView *)textView { + if ([self textSize].height != self.textHeightConstraint.constant) { + self.textHeightConstraint.constant = [self textSize].height; + [self layoutIfNeeded]; + } + [self.sendButton setEnabled:[self.textView.text length] > 0]; } - (IBAction)sendPressed:(id)sender { diff --git a/Juick/Views/MessageInputView.xib b/Juick/Views/MessageInputView.xib index 9cb8bd4..525d888 100644 --- a/Juick/Views/MessageInputView.xib +++ b/Juick/Views/MessageInputView.xib @@ -4,33 +4,42 @@ + + - - - + + - + - - + + - - - + + + + + + + - - -