SDTimeLineTableHeaderView.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. //
  2. // SDTimeLineTableHeaderView.m
  3. // GSD_WeiXin(wechat)
  4. //
  5. // Created by gsd on 16/2/25.
  6. // Copyright © 2016年 GSD. All rights reserved.
  7. //
  8. #import "SDTimeLineTableHeaderView.h"
  9. #import "UIView+SDAutoLayout.h"
  10. #import "SLNewMsgBgView.h"
  11. #import "SLMomentsNewsVc.h"
  12. #import "SLMsgBgSetVc.h"
  13. @implementation SDTimeLineTableHeaderView
  14. {
  15. UIImageView *_backgroundImageView;
  16. UIImageView *_iconView;
  17. UILabel *_nameLabel;
  18. UIScrollView *_interestcrollView;
  19. SLNewMsgBgView *_newMsgBgView;
  20. }
  21. - (instancetype)initWithFrame:(CGRect)frame
  22. {
  23. if (self = [super initWithFrame:frame]) {
  24. [self setup];
  25. }
  26. return self;
  27. }
  28. - (void)setup
  29. {
  30. _backgroundImageView = [UIImageView new];
  31. _backgroundImageView.image = ImageName(@"icon_moment_bg_01");
  32. _backgroundImageView.userInteractionEnabled = YES;
  33. [self addSubview:_backgroundImageView];
  34. _iconView = [UIImageView new];
  35. [self addSubview:_iconView];
  36. _nameLabel = [UILabel new];
  37. SLLoginInfo *targetModel = [SLGlobalInfo SharedInstance].loginInfo;
  38. _nameLabel.text = targetModel.user.userName;
  39. _nameLabel.textColor = [UIColor whiteColor];
  40. _nameLabel.textAlignment = NSTextAlignmentRight;
  41. _nameLabel.font = [UIFont boldSystemFontOfSize:15];
  42. [self addSubview:_nameLabel];
  43. _interestcrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
  44. _interestcrollView.bounces = NO;
  45. _interestcrollView.showsVerticalScrollIndicator = NO;
  46. _interestcrollView.showsHorizontalScrollIndicator = NO;
  47. [self addSubview:_interestcrollView];
  48. NSMutableArray *marr = [NSMutableArray arrayWithArray:@[@"运动",@"运动",@"运动",@"运动"]];
  49. [marr removeAllObjects];
  50. [marr enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
  51. UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
  52. label.text = obj;
  53. label.frame = CGRectMake(60 * idx, 0, 48, 26);
  54. label.textColor = [UIColor whiteColor];
  55. label.font = [UIFont systemFontOfSize:10];
  56. label.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.3];
  57. label.layer.cornerRadius = 13.0;
  58. label.textAlignment = NSTextAlignmentCenter;
  59. label.clipsToBounds = YES;
  60. [_interestcrollView addSubview:label];
  61. }];
  62. UIButton *moreInterestBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  63. [moreInterestBtn setImage:ImageName(@"icon_right_arrow_b") forState:UIControlStateNormal];
  64. [moreInterestBtn handleEvent:UIControlEventTouchUpInside withBlock:^{
  65. }];
  66. moreInterestBtn.hidden = YES;
  67. [self addSubview:moreInterestBtn];
  68. _newMsgBgView = [[SLNewMsgBgView alloc] initWithFrame:CGRectZero];
  69. _newMsgBgView.hidden = YES;
  70. [self addSubview:_newMsgBgView];
  71. _backgroundImageView.sd_layout.spaceToSuperView(UIEdgeInsetsMake(0, 0, 30, 0));
  72. UIView *topView = [[UIView alloc] init];
  73. topView.backgroundColor = [UIColor whiteColor];
  74. [self addSubview:topView];
  75. topView.sd_layout
  76. .heightIs(54)
  77. .leftSpaceToView(self, 0)
  78. .rightSpaceToView(self, 0)
  79. .topSpaceToView(self, -54);
  80. _iconView.sd_layout
  81. .widthIs(64)
  82. .heightIs(64)
  83. .leftSpaceToView(self, 16)
  84. .bottomSpaceToView(self, 84);
  85. _iconView.layer.cornerRadius = 32.0f;
  86. _iconView.clipsToBounds = YES;
  87. _iconView.contentMode = UIViewContentModeScaleAspectFill;
  88. _nameLabel.tag = 1000;
  89. [_nameLabel setSingleLineAutoResizeWithMaxWidth:200];
  90. _nameLabel.sd_layout
  91. .leftSpaceToView(_iconView, 9)
  92. .centerYEqualToView(_iconView)
  93. .heightIs(24);
  94. _interestcrollView.sd_layout
  95. .heightIs(26)
  96. .leftSpaceToView(self, 16)
  97. .rightSpaceToView(self, 50)
  98. .bottomSpaceToView(self, 54);
  99. moreInterestBtn.sd_layout
  100. .widthIs(26)
  101. .heightIs(26)
  102. .rightSpaceToView(self, 12)
  103. .centerYEqualToView(_interestcrollView);
  104. _newMsgBgView.sd_layout
  105. .centerXEqualToView(self)
  106. .bottomSpaceToView(self, 30)
  107. .widthIs(126)
  108. .heightIs(46);
  109. _newMsgBgView.layer.cornerRadius = 26.0;
  110. _newMsgBgView.clipsToBounds = YES;
  111. WS(weakSelf);
  112. [_newMsgBgView addTapWithBlock:^{
  113. SLMomentsNewsVc *vc = [SLMomentsNewsVc loadViewControllewWithNib];
  114. [weakSelf.viewController navPushViewController:vc animated:YES];
  115. SLLoginInfo *newLoginModel = [SLGlobalInfo SharedInstance].loginInfo;
  116. newLoginModel.user.momentsMsgNotice = @"";
  117. [SLGlobalInfo SharedInstance].loginInfo = newLoginModel;
  118. }];
  119. self.bgSelImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  120. self.bgSelImageView.image = ImageName(@"icon_moment_bg_sel");
  121. self.bgSelImageView.hidden = YES;
  122. [self addSubview:self.bgSelImageView];
  123. self.bgSelImageView.sd_layout
  124. .widthIs(56)
  125. .heightIs(56)
  126. .rightSpaceToView(self, 16)
  127. .centerYEqualToView(_iconView);
  128. [self.bgSelImageView addTapWithBlock:^{
  129. SLMsgBgSetVc *vc = [SLMsgBgSetVc loadViewControllewWithNib];
  130. [weakSelf.viewController navPushViewController:vc animated:YES];
  131. }];
  132. }
  133. - (void)confignHeaderWith:(SLUserModel *)userModel {
  134. NSString *urlStr = [userModel getUserHeadUrl];
  135. [_iconView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:ImageName(@"icon_ellipse")];
  136. _nameLabel.text = userModel.userName;
  137. NSString *bgImg = [NSString stringWithFormat:@"%@%@",[SLHttpCenter SharedInstance].serverUrl, userModel.friendCircleImage];
  138. [_backgroundImageView sd_setImageWithURL:[NSURL URLWithString:bgImg] placeholderImage:ImageName(@"icon_moment_bg_01")];
  139. }
  140. - (void)updateHeaderViewWith:(NSString *)momentsMsgNotice {
  141. if (momentsMsgNotice.length && [momentsMsgNotice integerValue]) {
  142. _backgroundImageView.sd_resetLayout.spaceToSuperView(UIEdgeInsetsMake(0, 0, 100, 0));
  143. _newMsgBgView.hidden = NO;
  144. _newMsgBgView.contentLabel.text = [NSString stringWithFormat:@"%@条新消息",momentsMsgNotice];
  145. }else {
  146. _backgroundImageView.sd_resetLayout.spaceToSuperView(UIEdgeInsetsMake(0, 0, 30, 0));
  147. _newMsgBgView.hidden = YES;
  148. }
  149. }
  150. @end