• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

iphone - 带有头像图像和带有时间戳的头像名称的气泡消息

[复制链接]
菜鸟教程小白 发表于 2022-12-12 15:25:17 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我必须使用 senders AVATARSender's name with time-stamps 来实现气泡消息,与下面的屏幕截图相同。

我已经成功实现了简单的气泡类型消息。现在我有一些很好的 Git-hub 项目可以提供给我,但我需要的是不同的东西。

我什至用过acanichat但没有运气。

所以任何人都可以建议我很好的教程吗?或者任何人已经用这个 Git-hub Library或与任何其他图书馆?

我想要一个带有发件人头像带有时间戳的发件人姓名的气泡消息,请看下图。

enter image description here

您的建议很重要。



Best Answer-推荐答案


您为什么不创建自己的聊天表?您只需要创建两个自定义单元,并在 XIB 文件的帮助下,您可以提供任何您想要的外观。

使用下面的微分器和条件。

- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath

{

 static NSString *CellIdentifier1 = @"Cell1";
 static NSString *CellIdentifier2 = @"Cell2";

CGSize boundingSize = CGSizeMake(messageWidth-20, 10000000);
CGSize itemTextSize = [messageText sizeWithFont:[UIFont systemFontOfSize:14]
                              constrainedToSize:boundingSize
                                  lineBreakMode:NSLineBreakByWordWrapping];
float textHeight = itemTextSize.height+7;


 if (messageType isEqualToString"textByme"]) { 

 CustomCell1  *cell = (CustomCell1 *)[self.tableview dequeueReusableCellWithIdentifier:CellIdentifier1];

        if (cell == nil) {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed"CustomCell1" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }



 UIImageView *bubbleImage=[[UIImageView alloc] initWithImage:[[UIImage imageNamed"chatbubble"] stretchableImageWithLeftCapWidth:15 topCapHeight:15]];
        bubbleImage.tag=55;
        [cell.contentView addSubview:bubbleImage];
        [bubbleImage setFrame:CGRectMake(255-itemTextSize.width,5,itemTextSize.width+10,textHeight)];
  UITextView *messageTextview=[[UITextView alloc]initWithFrame:CGRectMake(250-itemTextSize.width,0,itemTextSize.width+15, textHeight)];
        [cell.contentView addSubview:messageTextview];
        messageTextview.editable=NO;
        messageTextview.text = messageText;
        messageTextview.dataDetectorTypes=UIDataDetectorTypeAll;
        messageTextview.textAlignment=NSTextAlignmentJustified;
        messageTextview.font=[UIFont fontWithName"Helvetica Neue" size:13.0];
        messageTextview.backgroundColor=[UIColor clearColor];
        messageTextview.tag=indexPath.row;
        cell.Avatar_Image.image=[UIImage imageNamed"avatar.png"];
        cell.time_Label.text=data.messageTime;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        messageTextview.scrollEnabled=NO;

  return cell; 


}
else{

CustomCell2  *cell = (CustomCell2 *)[self.tableview dequeueReusableCellWithIdentifier:CellIdentifier2];

        if (cell == nil) {
            NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed"CustomCell2" owner:self options:nil];
            cell = [topLevelObjects objectAtIndex:0];
        }



   UIImageView *bubbleImage=[[UIImageView alloc] initWithImage:[[UIImage   imageNamed"chatbubble"] stretchableImageWithLeftCapWidth:15 topCapHeight:15]];
        [cell.contentView addSubview:bubbleImage];
        [bubbleImage setFrame:CGRectMake(50,5, itemTextSize.width+10, textHeight)];
        bubbleImage.tag=56;

        UITextView *messageTextview=[[UITextView alloc]initWithFrame:CGRectMake(50,0,itemTextSize.width+15, textHeight)];
        [cell.contentView addSubview:messageTextview];
        messageTextview.editable=NO;
        messageTextview.text = messageText;
        messageTextview.dataDetectorTypes=UIDataDetectorTypeAll;
        messageTextview.textAlignment=NSTextAlignmentJustified;
        messageTextview.backgroundColor=[UIColor clearColor];
        messageTextview.font=[UIFont fontWithName"Helvetica Neue" size:13.0];
        messageTextview.scrollEnabled=NO;
        messageTextview.tag=indexPath.row;
        cell.Avatar_Image.image=[UIImage imageNamed"avatar"];
        cell.time_Label.text=feed_data.messageTime;
        cell.selectionStyle=UITableViewCellSelectionStyleNone;

  return cell; 

}

}

高度:

- (CGFloat)tableViewUITableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath
{
float cellHeight;
        // text
        NSString *messageText = @"Your text";
        //
        CGSize boundingSize = CGSizeMake(messageWidth-20, 10000000);
        CGSize itemTextSize = [messageText sizeWithFont:[UIFont systemFontOfSize:14]
                                      constrainedToSize:boundingSize
                                          lineBreakMode:NSLineBreakByWordWrapping];

        // plain text
        cellHeight = itemTextSize.height;

        if (cellHeight<25) {

            cellHeight=25;
        }
        return cellHeight+30;
}

关于iphone - 带有头像图像和带有时间戳的头像名称的气泡消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19269564/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap