1

I'm building an messaging app, I use JSQMessageViewController to render messages and it's awesome. Now I have a little problem trying to customize the send button:

Basically I want to replace left and right BarButtonItem to customized button with images. After some hours of reading and searching, I got this far now:

button without text

button with text

As shown in the pictures, the voice button which is replacing the original send button is disabled if there is no text in the textField, this behavior is not what I want. How do I disable this behavior and make the button available all the time?

And this is how I customize the send button:

  UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  [rightButton setBackgroundImage:[UIImage imageNamed:@"AudioButton@2x.png"] forState:UIControlStateNormal];
  self.inputToolbar.contentView.rightBarButtonItem = rightButton;
Ray
  • 272
  • 2
  • 13

2 Answers2

1

if you want button available all the time, Find This method in "JSQMessagesInputToolbar.h" And Comment These lines in OLD Code

- (void)toggleSendButtonEnabled
{
BOOL hasText = [self.contentView.textView hasText];

//    if (self.sendButtonOnRight) {
//        self.contentView.rightBarButtonItem.enabled = hasText;
//    }

//    else {
//        self.contentView.leftBarButtonItem.enabled = hasText;
//    }

}

in New JSQ Code

- (void)updateSendButtonEnabledState
{
 if (!self.enablesSendButtonAutomatically) {
    return;
}

BOOL enabled = [self.contentView.textView hasText];
//    switch (self.sendButtonLocation) {
//        case JSQMessagesInputSendButtonLocationRight:
//            self.contentView.rightBarButtonItem.enabled = enabled;
//            break;
//        case JSQMessagesInputSendButtonLocationLeft:
//            self.contentView.leftBarButtonItem.enabled = enabled;
//            break;
//        default:
//            break;
//    }
}
0

this will work if you are replacing your custom button in rightBarButtonItem

add this in viewDidAppear

[self.inputToolbar.contentView.rightBarButtonItem setEnabled:YES];

and override textview delegate

-(void)textViewDidChange:(UITextView *)textView;
iNoob
  • 144
  • 1
  • 15