FocusOnCollectCell.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // FocusOnCollectCell.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/11/29.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "FocusOnCollectCell.h"
  9. @interface FocusOnCollectCell ()
  10. @property(nonatomic, strong) UIImageView *bgImageView;
  11. @property(nonatomic, strong) UIImageView *iconImageView;
  12. @property(nonatomic, strong) UILabel *nickNameLabel;
  13. @property(nonatomic, strong) UIButton *followBtn;
  14. @end
  15. static NSString *const image_name_bg = @"关注背景";
  16. static NSString *const image_name_btn = @"bogo_follow_btn";
  17. @implementation FocusOnCollectCell
  18. - (instancetype)initWithFrame:(CGRect)frame {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. [self initUI];
  22. }
  23. return self;
  24. }
  25. - (void)initUI{
  26. _bgImageView = ({
  27. UIImageView *imageView = [[UIImageView alloc] init];
  28. imageView.image = [UIImage imageNamed:image_name_bg];
  29. imageView;
  30. });
  31. _iconImageView = ({
  32. UIImageView *imageView = [[UIImageView alloc] init];
  33. imageView.clipsToBounds = YES;
  34. imageView.layer.cornerRadius = 25;
  35. imageView.userInteractionEnabled = YES;
  36. imageView.image = [UIImage imageNamed:@"com_preload_head_img"];
  37. UITapGestureRecognizer *tapImg = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImgView:)];
  38. [imageView addGestureRecognizer:tapImg];
  39. imageView;
  40. });
  41. _nickNameLabel= ({
  42. UILabel * label = [[UILabel alloc]init];
  43. label.textColor = [UIColor colorWithHexString:@"#666666"];
  44. label.font = [UIFont systemFontOfSize:14];
  45. label.textAlignment = NSTextAlignmentCenter;
  46. label.text = ASLocalizedString(@"小草莓");
  47. label;
  48. });
  49. _followBtn = ({
  50. UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  51. // [btn setBackgroundImage:[UIImage imageNamed:ASLocalizedString(@"bogo_follow_btn")] forState:UIControlStateNormal];
  52. btn.layer.borderColor = [UIColor colorWithHexString:@"B956D2"].CGColor;
  53. btn.backgroundColor = UIColor.whiteColor;
  54. btn.layer.borderWidth = 1;
  55. [btn setTitleColor:[UIColor colorWithHexString:@"B956D2"] forState:UIControlStateNormal];
  56. [btn setTitle:ASLocalizedString(@"+关注") forState:UIControlStateNormal];
  57. [btn.titleLabel sizeToFit];
  58. btn.titleLabel.font = [UIFont systemFontOfSize:13];
  59. btn.layer.cornerRadius = 25/2;
  60. btn.layer.masksToBounds = YES;
  61. [btn.titleLabel setAdjustsFontSizeToFitWidth:YES];
  62. [btn addTarget:self action:@selector(followAction) forControlEvents:UIControlEventTouchUpInside];
  63. btn;
  64. });
  65. [self.contentView addSubview:_bgImageView];
  66. [self.contentView addSubview:_iconImageView];
  67. [self.contentView addSubview:_nickNameLabel];
  68. [self.contentView addSubview:_followBtn];
  69. }
  70. - (void)followAction {
  71. if (self.followBlock) {
  72. self.followBlock();
  73. }
  74. // !self.followBlock ? : self.followBlock();
  75. }
  76. -(void)clickImgView:(UITapGestureRecognizer *)sender{
  77. if (self.clickImgBlock) {
  78. self.clickImgBlock(self.user.id);
  79. }
  80. }
  81. - (void)layoutSubviews {
  82. [super layoutSubviews];
  83. [_bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.edges.equalTo(self).insets(UIEdgeInsetsMake(0, 0, 0, 0));
  85. }];
  86. [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.top.mas_equalTo(kRealValue(15));
  88. make.centerX.equalTo(self);
  89. make.size.mas_equalTo(kRealValue(50));
  90. }];
  91. [_nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.equalTo(_iconImageView.mas_bottom).offset(kRealValue(3));
  93. make.width.mas_equalTo(self.contentView.width - kRealValue(15));
  94. make.centerX.equalTo(self);
  95. }];
  96. [_followBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  97. // make.bottom.mas_equalTo(-15);
  98. make.top.equalTo(_nickNameLabel.mas_bottom).offset(3);
  99. make.centerX.equalTo(self);
  100. make.width.mas_equalTo(kRealValue(52));
  101. make.height.mas_equalTo(kRealValue(25));
  102. }];
  103. }
  104. - (void)setUser:(HMHotItemModel *)user{
  105. _user = user;
  106. self.nickNameLabel.text = user.nick_name;
  107. [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:user.head_image] placeholderImage:kDefaultPreloadHeadImg];
  108. if ([user.id isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]) {
  109. self.followBtn.hidden = YES;
  110. }else{
  111. // self.followBtn.hidden = NO;
  112. }
  113. }
  114. @end