2
0

WFCFavoriteImageCell.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // WFCFavoriteUnknownCell.m
  3. // WildFireChat
  4. //
  5. // Created by Tom Lee on 2020/11/1.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #import "WFCFavoriteImageCell.h"
  9. @interface WFCFavoriteImageCell ()
  10. @property(nonatomic, strong)UIImageView *thumbView;
  11. @end
  12. @implementation WFCFavoriteImageCell
  13. - (void)awakeFromNib {
  14. [super awakeFromNib];
  15. // Initialization code
  16. }
  17. - (void)setFavoriteItem:(WFCUFavoriteItem *)favoriteItem {
  18. [super setFavoriteItem:favoriteItem];
  19. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[favoriteItem.data dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
  20. NSString *thumbStr = dict[@"thumb"];
  21. NSData *thumbData = [[NSData alloc] initWithBase64EncodedString:thumbStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
  22. UIImage *image = [UIImage imageWithData:thumbData];
  23. self.thumbView.frame = CGRectMake(0, 0, image.size.width, image.size.height);
  24. self.thumbView.image = image;
  25. }
  26. + (CGFloat)contentHeight:(WFCUFavoriteItem *)favoriteItem {
  27. NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[favoriteItem.data dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
  28. NSString *thumbStr = dict[@"thumb"];
  29. NSData *thumbData = [[NSData alloc] initWithBase64EncodedString:thumbStr options:NSDataBase64DecodingIgnoreUnknownCharacters];
  30. UIImage *image = [UIImage imageWithData:thumbData];
  31. return image.size.height;
  32. }
  33. - (UIImageView *)thumbView {
  34. if (!_thumbView) {
  35. _thumbView = [[UIImageView alloc] init];
  36. [self.contentArea addSubview:_thumbView];
  37. }
  38. return _thumbView;
  39. }
  40. @end