ios - 如何在消息气泡中添加时间标签?

标签 ios objective-c swift uicollectionview jsqmessagesviewcontroller

我在我的应用程序中使用 JSQMessageController,现在我想在我的气泡中添加时间标签。

here

我在我的目录中搜索,但没有找到图像 Assets 文件夹。但是当我在这里输入图像/ Assets 名称时:

我正在尝试这个:

override func collectionView(collectionView: JSQMessagesCollectionView!, attributedTextForCellBottomLabelAtIndexPath indexPath: NSIndexPath!) -> NSAttributedString! {
    let message: JSQMessage = self.messages[indexPath.item] as! JSQMessage
    return JSQMessagesTimestampFormatter.sharedFormatter().attributedTimestampForDate(message.date)
}

但这不是我想要的。我想将此标签添加到消息气泡中。

任何建议,即使是用 Objective-C 编写的?

最佳答案

请试试这个。它对我有用。

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView cellForItemAtIndexPath:indexPath];

    JSQMessage *message = [jsqmessages objectAtIndex:indexPath.item];
    //cell.messageBubbleTopLabel.text = message.senderDisplayName;
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
   [dateFormat setDateFormat:@"MMM dd, yyyy"];
    NSString *strDate = [dateFormat stringFromDate:message.date];
    cell.cellTopLabel.text = strDate;
    return cell;
}

关于ios - 如何在消息气泡中添加时间标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33911553/

相关文章:

ios - 使用 webRTC 时,在后台使用 iOS SDK 显示 "incoming call"屏幕

iphone - 检查NSArray中的每个唯一对象对

ios - 在所选区域中从 uiimagepickerviewcontroller 裁剪图像

iOS 键盘和文本字段

ios - 具有 r g b 值的 CAGradientLayer 不起作用 SWIFT

ios - 当我尝试创建从 UIWebview 到头文件的导出时,Xcode 崩溃

iphone - 如何使用 UIAlertStylePlainTextInput 样式在 UIAlertView 中格式化两个以上的按钮?

ios - swift中使用正则表达式检查十进制输入

swift - UIImagePickerController 视频最大尺寸

iphone - NSInteger 是一个 32 位整数吗