FriendListCell.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // FriendListCell.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/6.
  6. //
  7. #import "FriendListCell.h"
  8. #import <SDWebImage/UIImageView+WebCache.h>
  9. @interface FriendListCell()
  10. @end
  11. @implementation FriendListCell
  12. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  13. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  14. if (self) {
  15. [self setupViews];
  16. }
  17. return self;
  18. }
  19. - (void)setupViews {
  20. _avatar =[[UIImageView alloc] init];
  21. _avatar.frame=CGRectMake(8, 8, 50, 50);
  22. _avatar.contentMode = UIViewContentModeScaleAspectFill;
  23. _avatar.layer.cornerRadius = 25;
  24. _avatar.layer.masksToBounds = YES;
  25. _avatar.backgroundColor=[UIColor lightGrayColor];
  26. [self.contentView addSubview:_avatar];
  27. _name = [[UILabel alloc] init];
  28. _name.frame=CGRectMake(68, 8, 250, 50);
  29. _name.backgroundColor=[UIColor clearColor];
  30. [_name setFont:[UIFont boldSystemFontOfSize:18]];
  31. [_name setTextColor:[UIColor whiteColor]];
  32. [self.contentView addSubview:_name];
  33. }
  34. - (void)fillWithData:( NSDictionary*)data {
  35. // NSLog(@"fillWithData:%@",data);
  36. NSString *avatar =data[@"avatar"];
  37. if([avatar isKindOfClass:[NSString class]]){
  38. }
  39. else{
  40. avatar = @"";
  41. }
  42. [self.avatar sd_setImageWithURL:[NSURL URLWithString:avatar] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  43. self.name.text = data[@"name"];
  44. // tell constraints they need updating
  45. [self setNeedsUpdateConstraints];
  46. // update constraints now so we can animate the change
  47. [self updateConstraintsIfNeeded];
  48. [self layoutIfNeeded];
  49. }
  50. @end