产品要求给输入框加个Placeh,其实挺简略一性能,寻遍他们的官网https://www.rongcloud.cn/和文...://docs.rongcloud.cn/v4/都没有找到相干材料,事实很残暴,SDK 木有这个接口,只能本人实现了,思来想去,用了个笨办法,加个 UILabel 一试,还真行,有须要的您请往下看。

其实就是给输入框价格 UILabel,在该显示的时候显示,该暗藏的时候暗藏就完事儿了,代码如下:

  1. 在聊天页面增加一个 UILabel 属性
@property(nonatomic, strong) UILabel *placeholderLabel;
  1. 初始化并增加 placeholderLabel 对象
- (void)configPlaceholder {        //初始化和设置        self.placeholderLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 20)];    [self.chatSessionInputBarControl.inputTextView addSubview:self.placeholderLabel];    self.placeholderLabel.text = @"测试 Placeholder";        self.placeholderLabel.textColor = [UIColor grayColor];        self.placeholderLabel.userInteractionEnabled = YES;        //增加点击手势        UITapGestureRecognizer *tapLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPlaceholderLabel)];        [self.placeholderLabel addGestureRecognizer:tapLabel];}    - (void)tapPlaceholderLabel {        [self.chatSessionInputBarControl updateStatus:KBottomBarKeyboardStatus animated:YES];}
  1. 在内容发生变化和点击发送后,设置 placeholder 成果的显示
- (void)inputTextView:(UITextView *)inputTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {        //在内容发生变化和点击发送后,设置 placeholder 成果的显示        if ((range.location == 0 && [text isEqualToString:@""]) || [text isEqualToString:@""]) {                self.placeholderLabel.hidden = NO;            } else {                self.placeholderLabel.hidden = YES;            }}
  1. 还要提一下,融云的 SDK 有撤回音讯当前的“从新编辑”性能,在这个时候,要敞开 placeholder 成果的显示
- (void)didTapReedit:(RCMessageModel *)model {        self.placeholderLabel.hidden = YES;        [super didTapReedit:model];}

到这儿性能就实现了,placeholderLabel 的具体文字效果能够自行批改调整,心愿下面的代码能够帮到你,喜爱的话,点个赞吧。