JXtopShowVIew.m 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. //
  2. // JXtopShowVIew.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/21.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXtopShowVIew.h"
  9. #import "JXLabelObject.h"
  10. @interface JXtopShowVIew()
  11. @property (weak, nonatomic) IBOutlet UIView *topRightView;
  12. /** 期数*/
  13. @property (weak, nonatomic) IBOutlet UILabel *qishuL;
  14. /**球的IMG*/
  15. @property (weak, nonatomic) UIView *qiuIMG;
  16. @property (nonatomic,weak) UIView *saiziView;
  17. @property (weak, nonatomic) IBOutlet UILabel *hezhiLL;
  18. @property (nonatomic,copy) NSString *indexSubType;
  19. @property (nonatomic,copy) NSString *indexCarSubType;
  20. @property (nonatomic,strong) UIImageView *shaiziIMG;
  21. @property (nonatomic,weak) UIScrollView *topScorllView;
  22. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *hezhiConstraitH;
  23. /**底部View*/
  24. @property (weak, nonatomic) IBOutlet UIView *bottomView;
  25. @property (weak, nonatomic) IBOutlet UIButton *kaijjieguoBtn;
  26. @property (nonatomic,weak) UIButton *titBtn;
  27. @property (nonatomic,strong) NSMutableArray *dataArr2;
  28. @end
  29. @implementation JXtopShowVIew
  30. +(instancetype)xibJXtopShowVIew{
  31. return [[NSBundle mainBundle]loadNibNamed:@"JXtopShowVIew" owner:self options:nil].firstObject;
  32. }
  33. -(void)awakeFromNib{
  34. [super awakeFromNib];
  35. _dataArr2=[NSMutableArray array];
  36. _caizongBtn.layer.cornerRadius=8;
  37. _caizongBtn.layer.masksToBounds=YES;
  38. _tebieBtn.layer.cornerRadius=8;
  39. _tebieBtn.layer.masksToBounds=YES;
  40. _topRightView.layer.cornerRadius=8;
  41. _topRightView.layer.masksToBounds=YES;
  42. _kaijjieguoBtn.layer.cornerRadius=8;
  43. _kaijjieguoBtn.layer.masksToBounds=YES;
  44. //[g_notify addObserver:self selector:@selector(act_UserRoomAttention:) name:@"act_UserRoomAttention" object:nil];
  45. }
  46. -(void)setSelectItemModel:(JLSelectItemModel *)selectItemModel{
  47. _selectItemModel=selectItemModel;
  48. [_qiuIMG removeFromSuperview];
  49. UIView *qiuIMG = [[UIView alloc]init];
  50. qiuIMG.hidden=YES;
  51. [_topRightView addSubview:qiuIMG];
  52. self.qiuIMG=qiuIMG;
  53. [qiuIMG mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.centerY.mas_equalTo(_topRightView.mas_centerY);
  55. make.left.mas_equalTo(_qishuL.mas_right).mas_offset(8);
  56. make.right.mas_equalTo(_hezhiLL.mas_left).mas_offset(-5);
  57. make.height.mas_equalTo(20);
  58. }];
  59. [_saiziView removeFromSuperview];
  60. UIView *saiziView = [[UIView alloc]init];
  61. saiziView.hidden=YES;
  62. [_topRightView addSubview:saiziView];
  63. self.saiziView=saiziView;
  64. [saiziView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.centerY.mas_equalTo(_topRightView.mas_centerY);
  66. make.left.mas_equalTo(_qishuL.mas_right).mas_offset(8);
  67. make.right.mas_equalTo(_hezhiLL.mas_left).mas_offset(-5);
  68. make.height.mas_equalTo(20);
  69. }];
  70. NSLog(@"选择 %@",selectItemModel.subType);
  71. if ([selectItemModel.subType intValue]==2) {
  72. _indexCarSubType=@"";
  73. _indexSubType=selectItemModel.content;
  74. NSArray *imagesArr=[_indexSubType componentsSeparatedByString:@":"];
  75. _qishuL.text = [imagesArr firstObject];
  76. _hezhiLL.text=[imagesArr lastObject];
  77. }else if ([selectItemModel.subType intValue]==3) { //赛车
  78. _indexSubType=@"";
  79. _indexCarSubType=selectItemModel.content;
  80. NSArray *imagesArr=[_indexCarSubType componentsSeparatedByString:@":"];
  81. _qishuL.text = [imagesArr firstObject];
  82. _hezhiLL.text=[imagesArr lastObject];
  83. }else if ([selectItemModel.subType intValue]==4) { //标黄色
  84. _indexCarSubType=@"";
  85. _indexSubType=@"";
  86. NSArray *titleContent= [selectItemModel.content componentsSeparatedByString:@":"];
  87. NSMutableAttributedString *hintString1=[[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@%@%@",[titleContent firstObject],titleContent[1] ,[titleContent lastObject]]];
  88. NSRange range2=[[hintString1 string]rangeOfString:titleContent[1]];
  89. [hintString1 addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:range2];
  90. _qishuL.attributedText = hintString1;
  91. _hezhiLL.text=[titleContent lastObject];
  92. self.hezhiConstraitH.constant=140+40;
  93. _saiziView.hidden=YES;
  94. _qiuIMG.hidden=YES;
  95. }else{
  96. _qishuL.text = selectItemModel.content;
  97. _saiziView.hidden=YES;
  98. _qiuIMG.hidden=YES;
  99. self.hezhiConstraitH.constant=140+40;
  100. }
  101. //CGFloat qishuSize=[self titleBtnWight:_qishuL.text and:_qishuL].width;
  102. if (_indexCarSubType.length>0) {
  103. _saiziView.hidden=NO;
  104. _qiuIMG.hidden=YES;
  105. NSArray *imagesArr=[_indexCarSubType componentsSeparatedByString:@":"];
  106. NSArray *numberS=[imagesArr[1] componentsSeparatedByString:@","];
  107. self.hezhiConstraitH.constant=45+numberS.count*21+40;
  108. for (int i=0; i<numberS.count; i++) {
  109. _shaiziIMG = [[UIImageView alloc] init];
  110. if ([numberS[i] intValue]==10) {
  111. _shaiziIMG.image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",numberS[i]]];
  112. }else{
  113. _shaiziIMG.image=[UIImage imageNamed:[NSString stringWithFormat:@"0%@",numberS[i]]];
  114. }
  115. [_saiziView addSubview:_shaiziIMG];
  116. _shaiziIMG.frame=CGRectMake(0 +i*(20+1), 0, 20, 20);
  117. }
  118. _hezhiLL.text=[NSString stringWithFormat:@"%@",[imagesArr lastObject]];
  119. }
  120. if (_indexSubType.length>0) {
  121. _saiziView.hidden=YES;
  122. _qiuIMG.hidden=NO;
  123. NSArray *imagesArr=[_indexSubType componentsSeparatedByString:@":"];
  124. NSArray *numberS=[imagesArr[1] componentsSeparatedByString:@","];
  125. self.hezhiConstraitH.constant=45+numberS.count*21+40;
  126. for (int i=0; i<numberS.count; i++) {
  127. _shaiziIMG = [[UIImageView alloc] init];
  128. _shaiziIMG.image=[UIImage imageNamed:[NSString stringWithFormat:@"shaizi%@",numberS[i]]];
  129. [_qiuIMG addSubview:_shaiziIMG];
  130. _shaiziIMG.frame=CGRectMake(0 +i*(20+1), 0, 20, 20);
  131. }
  132. _hezhiLL.text=[NSString stringWithFormat:@"%@",[imagesArr lastObject]];
  133. }
  134. }
  135. -(CGSize)titleBtnWight:(NSString *)titBtnW and:(UILabel *)titBtn {
  136. CGSize titleSize = [titBtnW boundingRectWithSize:CGSizeMake(MAXFLOAT, 24) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.font} context:nil].size;
  137. return titleSize;
  138. }
  139. /*
  140. - (void)act_UserRoomAttention:(NSNotification *)note{
  141. NSDictionary *dict=note.userInfo;
  142. NSArray *tempArr=dict[@"user"];
  143. _dataArr2=[tempArr mutableCopy];
  144. CGFloat titBtnX =10;
  145. for(int i =0; i <tempArr.count; i++){
  146. memberData *model=tempArr[i];
  147. UIButton *titBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  148. titBtn.titleLabel.font= [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
  149. [titBtn setTitleColor:kRGBColor51 forState:UIControlStateNormal];
  150. [titBtn setTitle:model.userNickName forState:UIControlStateNormal];
  151. titBtn.backgroundColor=[UIColor whiteColor];
  152. titBtn.layer.cornerRadius=10;
  153. titBtn.layer.masksToBounds=YES;
  154. titBtn.tag=i;
  155. CGSize titleSize=[self titleBtnWightBtb:model.userNickName and:titBtn];
  156. CGFloat titBtnW = titleSize.width+5;
  157. titBtn.frame=CGRectMake(titBtnX, 6, titBtnW, 24);
  158. titBtnX += titBtnW + 10;
  159. [ self.topScorllView addSubview:titBtn];
  160. self.titBtn=titBtn;
  161. [titBtn addTarget:self action:@selector(titleUserBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  162. }
  163. self.topScorllView.contentSize=CGSizeMake(_dataArr2.count *(64)+100, 0);
  164. }
  165. */
  166. - (void)titleUserBtnClick:(UIButton *)btn{
  167. if (_jxGuanXinBlockBtn) {
  168. _jxGuanXinBlockBtn(btn);
  169. }
  170. }
  171. //json格式字符串转字典:
  172. - (NSArray *)dictionaryWithJsonString:(NSString *)jsonString {
  173. if (jsonString == nil) {
  174. return nil;
  175. }
  176. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  177. NSError *err;
  178. NSArray *dic = [NSJSONSerialization JSONObjectWithData:jsonData
  179. options:NSJSONReadingMutableContainers
  180. error:&err];
  181. if(err) {
  182. NSLog(@"json解析失败:%@",err);
  183. return nil;
  184. }
  185. return dic;
  186. }
  187. -(CGSize)titleBtnWightBtb:(NSString *)titBtnW and:(UIButton *)titBtn {
  188. CGSize titleSize = [titBtnW boundingRectWithSize:CGSizeMake(MAXFLOAT, 24) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:titBtn.titleLabel.font} context:nil].size;
  189. return titleSize;
  190. }
  191. @end