Created
June 24, 2020 06:34
-
-
Save alanzeino/1589a2358572534d52912ee4865dcc38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static UICollectionViewListCell *userCell(UICollectionView *collectionView, NSIndexPath *indexPath, NSArray<RTTweet *> *tweets) { | |
UICollectionViewListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UserCell" forIndexPath:indexPath]; | |
UIListContentConfiguration *contentConfiguration = [UIListContentConfiguration valueCellConfiguration]; | |
contentConfiguration.image = nil; | |
RTTweet *tweet = tweets[indexPath.row]; | |
contentConfiguration.text = tweet.user.username; | |
contentConfiguration.secondaryText = [tweet.user.followers az_formattedStringForCount]; | |
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:tweet.user.profileUrlFull] | |
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | |
if (data) { | |
UIImage *image = [UIImage imageWithData:data]; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
contentConfiguration.image = image; | |
}); | |
} | |
}); | |
}] resume]; | |
contentConfiguration.imageProperties.cornerRadius = 22.f; | |
contentConfiguration.imageProperties.maximumSize = CGSizeMake(44.f, 44.f); | |
cell.contentConfiguration = contentConfiguration; | |
return cell; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment