3

アプリで JSQMessageController を使用していますが、バブル内に時間ラベルを追加したいと考えています。

ここ

ディレクトリを検索しましたが、画像アセット フォルダーが見つかりませんでした。しかし、ここに画像/アセット名を入力すると:

私はこれを試しています:

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で書かれたものでも、何か提案はありますか?

4

3 に答える 3

1

これを試してください。それは私のために働くでしょう。

- (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;
}
于 2016-11-21T10:59:48.823 に答える
0

時間ラベルを追加する場合は、JSQMessagesCollectionViewCellOutgoing の xib ファイルと着信バブルも変更する必要があります。

于 2017-07-09T10:02:54.930 に答える
-1

私が見つけた最良のアプローチは、 and をサブクラスJSQMessagesCollectionViewCellIncoming化することでしたJSQMessagesCollectionViewCellOutgoing。これは非常に重要です。ライブラリはこれらの型のいずれかを想定しているため、JSQMessagesCollectionViewCell直接サブクラス化すると問題が発生します。ところで、既存の をコピーし、JSQMessagesCollectionViewCellOutgoing.xibすべてJSQMessagesCollectionViewCellIncoming.xibを変更/名前変更したため、セルのカスタマイズを簡単に開始できました。

次に、JSQMessagesViewController サブクラスで、次のように viewDidLoad() にセル識別子を登録します。

    self.outgoingCellIdentifier = [CustomCollectionViewCellOutgoing cellReuseIdentifier];
    self.outgoingMediaCellIdentifier = [CustomCollectionViewCellOutgoing mediaCellReuseIdentifier];

    [self.collectionView registerNib:[CustomCollectionViewCellOutgoing nib] forCellWithReuseIdentifier:self.outgoingCellIdentifier];
    [self.collectionView registerNib:[CustomCollectionViewCellOutgoing nib] forCellWithReuseIdentifier:self.outgoingMediaCellIdentifier];

    self.incomingCellIdentifier = [CustomCollectionViewCellIncoming cellReuseIdentifier];
    self.incomingMediaCellIdentifier = [CustomCollectionViewCellIncoming mediaCellReuseIdentifier];

    [self.collectionView registerNib:[CustomCollectionViewCellIncoming nib] forCellWithReuseIdentifier:self.incomingCellIdentifier];

次に、collectionView:cellForItemAtIndexPath: でカスタム セルにアクセスできます。

[self.collectionView registerNib:[CustomCollectionViewCellIncoming nib] forCellWithReuseIdentifier:self.incomingMediaCellIdentifier];

回答元リンク: https://github.com/jessesquires/JSQMessagesViewController/issues/1233

于 2016-11-21T08:46:17.520 に答える