BogoNewsHeadView.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // BogoNewsHeadView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/4/13.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoNewsHeadView.h"
  9. @implementation BogoNewsHeadView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setUpView];
  15. }
  16. return self;
  17. }
  18. -(void)clickBtn:(UIButton *)sender{
  19. if (self.delegate && [self.delegate respondsToSelector:@selector(clickHeadControl:)]) {
  20. [self.delegate clickHeadControl:sender.tag - 100];
  21. }
  22. }
  23. - (void)setModel:(BogoNewsTabNumModel *)model{
  24. QMUIButton *likeBtn = [self viewWithTag:100];
  25. QMUIButton *replyBtn = [self viewWithTag:100 + 1];
  26. likeBtn.shouldHideBadgeAtZero = YES;
  27. likeBtn.badgeValue = [NSString stringWithFormat:@"%ld",model.bzone_like];
  28. likeBtn.badgeOriginX = likeBtn.width / 2 + 10;
  29. likeBtn.badgeOriginY = likeBtn.top + 10;
  30. replyBtn.shouldHideBadgeAtZero = YES;
  31. replyBtn.badgeValue = [NSString stringWithFormat:@"%ld",model.bzone_reply];
  32. replyBtn.badgeOriginX = replyBtn.width / 2 + 10;
  33. replyBtn.badgeOriginY = replyBtn.top + 10;
  34. }
  35. -(void)setUpView{
  36. NSArray *listArr = @[ASLocalizedString(@"点赞"),ASLocalizedString(@"评论"),ASLocalizedString(@"粉丝"),ASLocalizedString(@"关注")];
  37. NSArray *imgArr = @[@"bogo_news_top_likes",@"bogo_news_top_comment",@"bogo_news_top_fans",@"bogo_news_top_concert"];
  38. CGFloat viewWidth = kScreenW / 4;
  39. for (int i = 0; i < 4; i ++) {
  40. QMUIButton *btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  41. btn.frame = CGRectMake(viewWidth * i, 0, viewWidth, viewWidth);
  42. [btn setTitleColor:[UIColor colorWithHexString:@"#333333"] forState:UIControlStateNormal];
  43. [btn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateNormal];
  44. [btn setTitle:listArr[i] forState:UIControlStateNormal];
  45. btn.tag = 100 + i;
  46. btn.titleLabel.font = [UIFont systemFontOfSize:16];
  47. btn.imagePosition = QMUIButtonImagePositionTop;
  48. btn.spacingBetweenImageAndTitle = 10;
  49. [btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  50. // btn.backgroundColor = ;
  51. [self addSubview:btn];
  52. UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 48, 48)];
  53. bg.backgroundColor = UIColor.whiteColor;
  54. bg.layer.cornerRadius = 24;
  55. bg.layer.masksToBounds = YES;
  56. [btn insertSubview:bg belowSubview:btn.imageView];
  57. [bg mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.size.mas_equalTo(bg.size);
  59. make.center.mas_equalTo(btn.imageView);
  60. }];
  61. }
  62. }
  63. @end