JSQMessageViewController自定义发送按钮

射线

我正在构建一个消息传递应用程序,我使用JSQMessageViewController呈现消息,它很棒。现在我在尝试自定义发送按钮时遇到了一些问题:

基本上我想用图像替换左右BarButtonItem到自定义按钮。经过几个小时的阅读和搜索,我到现在为止:

没有文字的按钮

带有文字的按钮

如图所示,如果textField中没有文本,则替换原始发送按钮的语音按钮将被禁用,这种行为不是我想要的。如何禁用此行为并使按钮始终可用?

这就是我自定义发送按钮的方式:

  UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
  [rightButton setBackgroundImage:[UIImage imageNamed:@"[email protected]"] forState:UIControlStateNormal];
  self.inputToolbar.contentView.rightBarButtonItem = rightButton;
Varinder Singh iPhone开发人员

如果您希望按钮始终可用,请在“ JSQMessagesInputToolbar.h”中找到此方法,并在旧代码中注释这些行

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

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

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

}

在新的JSQ代码中

- (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;
//    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章