EMAvatarNameCell.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // EMAvatarNameCell.m
  3. // ChatDemo-UI3.0
  4. //
  5. // Created by XieYajie on 2019/1/9.
  6. // Copyright © 2019 XieYajie. All rights reserved.
  7. //
  8. #import "EMAvatarNameCell.h"
  9. @implementation EMAvatarNameCell
  10. - (instancetype)initWithStyle:(UITableViewCellStyle)style
  11. reuseIdentifier:(NSString *)reuseIdentifier
  12. {
  13. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  14. if (self) {
  15. [self _setupSubviews];
  16. }
  17. return self;
  18. }
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. // Initialization code
  22. }
  23. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  24. [super setSelected:selected animated:animated];
  25. // Configure the view for the selected state
  26. }
  27. #pragma mark - Subviews
  28. - (void)_setupSubviews
  29. {
  30. self.selectionStyle = UITableViewCellSelectionStyleNone;
  31. _avatarView = [[UIImageView alloc] init];
  32. [self.contentView addSubview:_avatarView];
  33. [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
  34. make.top.equalTo(self.contentView).offset(8);
  35. make.left.equalTo(self.contentView).offset(15);
  36. make.bottom.equalTo(self.contentView).offset(-8);
  37. make.width.equalTo(self.avatarView.mas_height).multipliedBy(1);
  38. }];
  39. _detailLabel = [[UILabel alloc] init];
  40. _detailLabel.backgroundColor = [UIColor clearColor];
  41. _detailLabel.font = [UIFont systemFontOfSize:15];
  42. _detailLabel.textColor = [UIColor grayColor];
  43. [self.contentView addSubview:_detailLabel];
  44. [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.left.equalTo(self.avatarView.mas_right).offset(8);
  46. make.right.equalTo(self.contentView).offset(-15);
  47. make.bottom.equalTo(self.contentView).offset(-8);
  48. }];
  49. _nameLabel = [[UILabel alloc] init];
  50. _nameLabel.numberOfLines = 2;
  51. _nameLabel.backgroundColor = [UIColor clearColor];
  52. _nameLabel.textColor = [UIColor blackColor];
  53. _nameLabel.font = [UIFont systemFontOfSize:18];
  54. [self.contentView addSubview:_nameLabel];
  55. [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.equalTo(self.contentView).offset(8);
  57. make.left.equalTo(self.avatarView.mas_right).offset(8);
  58. make.right.equalTo(self.contentView).offset(-15);
  59. make.bottom.equalTo(self.detailLabel.mas_top);
  60. }];
  61. }
  62. #pragma mark - Public
  63. - (void)setAccessoryButton:(UIButton *)accessoryButton
  64. {
  65. _accessoryButton = accessoryButton;
  66. if (_accessoryButton) {
  67. [_accessoryButton addTarget:self action:@selector(accessoryButtonAction) forControlEvents:UIControlEventTouchUpInside];
  68. }
  69. self.accessoryView = accessoryButton;
  70. }
  71. #pragma mark - Action
  72. - (void)accessoryButtonAction
  73. {
  74. if (_delegate && [_delegate respondsToSelector:@selector(cellAccessoryButtonAction:)]) {
  75. [_delegate cellAccessoryButtonAction:self];
  76. }
  77. }
  78. @end