gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:39:44 24 4
gpt4 key购买 nike

我必须使用 senders AVATARSender's name with time-stamps 实现气泡消息,如下图所示。

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

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

所以有人可以推荐我一个好的教程吗?或者任何人已经用这个 Git-hub Library 做过还是与任何其他图书馆?

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

enter image description here

您的建议很重要。

最佳答案

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

使用区分符和条件,如下所示。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)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)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com