JxnoticeScrollView.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // JxnoticeScrollView.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/1.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JxnoticeScrollView.h"
  9. #import "JXLabelObject.h"
  10. #import "JLSelectModel.h"
  11. @interface JxnoticeScrollView ()
  12. @property (nonatomic,strong) UIView *noticeView ;
  13. @end
  14. @implementation JxnoticeScrollView
  15. -(instancetype)initWithFrame:(CGRect)frame{
  16. if (self=[super initWithFrame:frame]) {
  17. _noticeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 40)];
  18. _noticeView.backgroundColor = [UIColor whiteColor];
  19. _noticeView.userInteractionEnabled=YES;
  20. _noticeView.hidden = NO;
  21. [self addSubview:_noticeView];
  22. _noticeLabel = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 80, 40)];
  23. _noticeLabel.titleLabel.font=[UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
  24. [_noticeLabel setTitle:@"特别关心" forState:UIControlStateNormal];
  25. [_noticeLabel setTitleColor:HEXCOLOR(0x323232) forState:UIControlStateNormal];
  26. [_noticeView addSubview:_noticeLabel];
  27. [_noticeLabel addTarget:self action:@selector(noticeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  28. _noticeTitleScrolView = [[UIScrollView alloc] initWithFrame:CGRectMake(80, 0, JX_SCREEN_WIDTH-95, 40)];
  29. _noticeTitleScrolView.userInteractionEnabled=YES;
  30. [self addSubview:_noticeTitleScrolView];
  31. [g_notify addObserver:self selector:@selector(act_UserRoomAttention:) name:@"act_UserRoomAttention222" object:nil];
  32. }
  33. return self;
  34. }
  35. -(CGSize)titleBtnWight:(NSString *)titBtnW and:(UIButton *)titBtn {
  36. CGSize titleSize = [titBtnW boundingRectWithSize:CGSizeMake(MAXFLOAT, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.titleLabel.font} context:nil].size;
  37. return titleSize;
  38. }
  39. - (void)act_UserRoomAttention:(NSNotification *)note{
  40. NSDictionary *dict=note.userInfo;
  41. NSArray *tempArr=dict[@"user"];
  42. _dataArr=[tempArr mutableCopy];
  43. CGFloat titBtnX =10;
  44. for(int i =0; i <tempArr.count; i++){
  45. memberData *model=tempArr[i];
  46. UIButton *titBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  47. [titBtn setTitleColor:kRGBColor51 forState:UIControlStateNormal];
  48. [titBtn setTitle:model.userNickName forState:UIControlStateNormal];
  49. titBtn.titleLabel.font=[UIFont systemFontOfSize:14 weight:UIFontWeightRegular];
  50. titBtn.backgroundColor=[UIColor whiteColor];
  51. titBtn.layer.cornerRadius=10;
  52. titBtn.layer.masksToBounds=YES;
  53. titBtn.tag=i;
  54. CGSize titleSize=[self titleBtnWight:model.userNickName and:titBtn];
  55. CGFloat titBtnW = titleSize.width+5;
  56. titBtn.frame=CGRectMake(titBtnX, 6, titBtnW, 24);
  57. titBtnX += titBtnW + 15;
  58. [_noticeTitleScrolView addSubview:titBtn];
  59. [titBtn addTarget:self action:@selector(titleUserBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  60. }
  61. self.noticeTitleScrolView.contentSize=CGSizeMake(_dataArr.count *(64)+100, 0);
  62. }
  63. - (void)noticeBtnClick:(UIButton *)btn{
  64. if (_jxnoticeScrollViewBtnBlock2) {
  65. _jxnoticeScrollViewBtnBlock2(btn);
  66. }
  67. }
  68. - (void)titleUserBtnClick:(UIButton *)btn{
  69. if (_jxnoticeScrollViewBtnBlock) {
  70. _jxnoticeScrollViewBtnBlock(btn);
  71. }
  72. }
  73. @end