DrawerCell.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // DrawerCell.m
  3. // smartRhino
  4. //
  5. // Created by tederen on 2019/10/21.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "DrawerCell.h"
  9. @interface DrawerCell ()
  10. @property (nonatomic, strong) UILabel *titleLabel;
  11. @property (nonatomic, strong) UIImageView *avatarImageView;
  12. @property (nonatomic, strong) UIImageView *arrowImageView;
  13. @end
  14. @implementation DrawerCell
  15. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  16. {
  17. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  18. if (self) {
  19. // Initialization code
  20. [self.contentView addSubview:self.avatarImageView];
  21. [self.contentView addSubview:self.titleLabel];
  22. [self.contentView addSubview:self.arrowImageView];
  23. [_avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  24. make.leading.equalTo(self.contentView).offset(33);
  25. make.centerY.equalTo(self.contentView);
  26. }];
  27. [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.leading.equalTo(self.contentView).offset(80);
  29. make.trailing.equalTo(_arrowImageView.mas_leading).offset(23);
  30. make.centerY.equalTo(_avatarImageView);
  31. }];
  32. [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make){
  33. make.trailing.equalTo(self.contentView).offset(-23);
  34. make.centerY.equalTo(self.contentView);
  35. make.size.mas_equalTo(CGSizeMake(7, 12));
  36. }];
  37. }
  38. return self;
  39. }
  40. #pragma mark - publicMethod
  41. - (void)loadCellDataWithTitle:(NSString *)title imageName:(NSString *)imageName
  42. {
  43. _titleLabel.text = title;
  44. [_titleLabel sizeToFit];
  45. [_avatarImageView setImage:IMG(imageName)];
  46. [_avatarImageView mas_updateConstraints:^(MASConstraintMaker *make) {
  47. make.size.mas_equalTo(IMG(imageName).size);
  48. }];
  49. }
  50. #pragma mark - setter/getter
  51. - (UILabel *)titleLabel
  52. {
  53. if (!_titleLabel) {
  54. _titleLabel = [UILabel new];
  55. _titleLabel.textColor = UIColorHex(232323);
  56. _titleLabel.font = [UIFont systemFontOfSize:17];
  57. }
  58. return _titleLabel;
  59. }
  60. - (UIImageView *)avatarImageView
  61. {
  62. if (!_avatarImageView) {
  63. _avatarImageView = [UIImageView new];
  64. _avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
  65. }
  66. return _avatarImageView;
  67. }
  68. - (UIImageView *)arrowImageView
  69. {
  70. if (!_arrowImageView) {
  71. _arrowImageView = [[UIImageView alloc] initWithImage:IMG(@"icon_arrowRight")];
  72. }
  73. return _arrowImageView;
  74. }
  75. @end