LoginSignup
3
5

More than 5 years have passed since last update.

JSQMessagesViewController

Last updated at Posted at 2016-03-20

JSQMessagesCollectionViewのTop位置調整

self.topContentAdditionalInset = {Top位置};

JSQMessagesCollectionViewCellの初期スクロール位置調整

self.automaticallyScrollsToMostRecentMessage = NO;
[self.collectionView reloadData];
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:{行番号} inSection:0] 
                            atScrollPosition:UICollectionViewScrollPositionCenteredVertically
                                    animated:NO];

吹き出しのテキストカラーが一部黒字になってしまう場合の対処法

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    JSQMessagesCollectionViewCell *cell = (JSQMessagesCollectionViewCell *)[super collectionView:collectionView
                                                                          cellForItemAtIndexPath:indexPath];
    cell.textView.textColor = [UIColor whiteColor];
    return cell;
}

吹き出し画像の非同期取得

JSQPhotoMediaItem *item = [JSQPhotoMediaItem new];
message = [[JSQMessage alloc] initWithSenderId:{SenderID}
                             senderDisplayName:{SenderName}
                                          date:{Date}
                                         media:item];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    NSURL *url = [NSURL URLWithString:@"{画像URL}"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    item.image = [[UIImage alloc] initWithData:data cache:NO];

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.collectionView reloadData];
    });
});

[_messages addMessage:message];

吹き出しの上部に送受信時刻を表示

// CellTopLabelの表示位置
- (CGFloat)collectionView:(JSQMessagesCollectionView *)collectionView
                   layout:(JSQMessagesCollectionViewFlowLayout *)collectionViewLayout
                   heightForCellTopLabelAtIndexPath:(NSIndexPath *)indexPath
{
    // default:20.0f
    return kJSQMessagesCollectionViewCellLabelHeightDefault;
}

// CellTopLabelの表示
- (NSAttributedString *)collectionView:(JSQMessagesCollectionView *)collectionView
                   attributedTextForCellTopLabelAtIndexPath:(NSIndexPath *)indexPath
{
    return [[JSQMessagesTimestampFormatter sharedFormatter] attributedTimestampForDate:{送受信時刻}];
}
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5