暂无描述

KXNewTeachViewController.m 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // KXNewTeachViewController.m
  3. // CAISHEN
  4. //
  5. // Created by 小花 on 2017/11/8.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXNewTeachViewController.h"
  9. #import "KXTeachCycleView.h"
  10. #import "KXTeachCollectionViewCell.h"
  11. #import "KXNewsWebViewController.h"
  12. #import "KXNewTeachCollectionViewCell.h"
  13. #import "KXHouseCalculateViewController.h"
  14. #import "KXEqualRateToolViewController.h"
  15. #import "KXIndividualIncomeViewController.h"
  16. #import "KXInstallmentViewController.h"
  17. #import "KXCarLoancalViewController.h"
  18. @interface KXNewTeachViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,KXTeachCycleViewDelegate>
  19. @property (nonatomic,strong)KXTeachCycleView *teachCycle;
  20. @property (nonatomic,strong)UICollectionView *collectionView;
  21. @property (nonatomic,strong)NSMutableArray *bannnerArray;
  22. @property (nonatomic,strong)NSMutableArray *dataSource;
  23. @property (nonatomic, strong) NSArray *titleArr;
  24. @property (nonatomic, strong) NSArray *imageAarr;
  25. @end
  26. @implementation KXNewTeachViewController
  27. {
  28. UIView *headerView;
  29. }
  30. - (void)viewDidLoad {
  31. [super viewDidLoad];
  32. // Do any additional setup after loading the view.
  33. self.view.backgroundColor = [UIColor whiteColor];
  34. [self createCollectionView];
  35. [self requestDataSource];
  36. }
  37. - (void)createCollectionView
  38. {
  39. self.name = @"工具";
  40. headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250)];
  41. headerView.backgroundColor = [UIColor whiteColor];
  42. UILabel *teachLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
  43. teachLabel.text = @"";
  44. teachLabel.textColor = [UIColor titleColor];
  45. teachLabel.font = FONT_SYS(16);
  46. teachLabel.textAlignment = NSTextAlignmentLeft;
  47. [headerView addSubview:teachLabel];
  48. self.teachCycle = [[KXTeachCycleView alloc]initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH - 15, 160)];
  49. self.teachCycle.delegate = self;
  50. [headerView addSubview:self.teachCycle];
  51. UILabel *grayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 210, SCREEN_WIDTH, 5)];
  52. grayLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
  53. [headerView addSubview:grayLabel];
  54. UILabel *programLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 220, 100, 20)];
  55. programLabel.text = @"理财工具";
  56. programLabel.textColor = [UIColor titleColor];
  57. programLabel.font = FONT_SYS(16);
  58. programLabel.textAlignment = NSTextAlignmentLeft;
  59. [headerView addSubview:programLabel];
  60. UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
  61. flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-1)/2, Fitsize(122));
  62. flowLayout.minimumLineSpacing = 1;
  63. flowLayout.minimumInteritemSpacing = 1;
  64. flowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 250);
  65. self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavHeight - TabbarHeight) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[KXNewTeachCollectionViewCell class] forCellWithReuseIdentifier:@"newTeach"];
  66. self.collectionView.backgroundColor = [UIColor KXColorWithHex:0xeeeeed];
  67. self.collectionView.delegate = self;
  68. self.collectionView.dataSource = self;
  69. [self.view addSubview: self.collectionView];
  70. [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionViewHeader"];
  71. }
  72. #pragma mark 请求数据
  73. -(void)requestDataSource
  74. {
  75. NSString *urlString=[NSString stringWithFormat:@"%@/information/getinformationsbypackage",URL];
  76. NSDictionary *paraDict=@{@"package_id":@"package_1",@"classification_id":@"贷款",@"page":@(1)};
  77. [KXHTTP post:urlString params:paraDict success:^(id json) {
  78. NSMutableArray *bannerImageArray=[NSMutableArray arrayWithCapacity:0];
  79. if (self.bannnerArray.count==0) {
  80. for (NSDictionary *dict in json[@"ios_teach_banner"]) {
  81. [self.bannnerArray addObject:dict];
  82. [bannerImageArray addObject:dict[@"thumbnail"]];
  83. }
  84. _teachCycle.cycleArray=bannerImageArray;
  85. }
  86. NSArray *array=[NSArray yy_modelArrayWithClass:[KXNewsModel class] json:[json[@"listdata"] valueForKey:@"data"]];
  87. for (KXNewsModel *model in array) {
  88. [self.dataSource addObject:model];
  89. }
  90. [self.collectionView reloadData];
  91. } failure:^(NSError *error) {
  92. }];
  93. }
  94. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  95. {
  96. return self.titleArr.count;
  97. }
  98. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  99. {
  100. KXNewTeachCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newTeach" forIndexPath:indexPath];
  101. [cell setTitle:self.titleArr[indexPath.row] andImage:self.imageAarr[indexPath.row]];
  102. return cell;
  103. }
  104. - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
  105. {
  106. NSString *CellIdentifier = @"UICollectionViewHeader";
  107. //从缓存中获取 Headercell
  108. UICollectionReusableView *cell = (UICollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
  109. [cell addSubview:headerView];
  110. return cell;
  111. }
  112. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  113. {
  114. if (indexPath.item == 0) {
  115. KXHouseCalculateViewController *houseCalcul = [[KXHouseCalculateViewController alloc] init];
  116. [self.navigationController pushViewController:houseCalcul animated:YES];
  117. }
  118. if (indexPath.item == 1) {
  119. KXCarLoancalViewController *carloanVC = [[KXCarLoancalViewController alloc]init];
  120. [self.navigationController pushViewController:carloanVC animated:YES];
  121. }
  122. if (indexPath.item == 2) {
  123. KXInstallmentViewController *vc = [[KXInstallmentViewController alloc] init];
  124. [self.navigationController pushViewController:vc animated:YES];
  125. }
  126. if (indexPath.item == 3) {
  127. KXIndividualIncomeViewController *vc = [[KXIndividualIncomeViewController alloc] init];
  128. [self.navigationController pushViewController:vc animated:YES];
  129. }
  130. if (indexPath.item == 4) {
  131. KXEqualRateToolViewController *equRateTool = [[KXEqualRateToolViewController alloc] init];
  132. equRateTool.equalType = EqualMoneyType;
  133. [self.navigationController pushViewController:equRateTool animated:YES];
  134. }
  135. if (indexPath.item == 5) {
  136. KXEqualRateToolViewController *equalRate = [[KXEqualRateToolViewController alloc] init];
  137. equalRate.equalType = EqualRateType;
  138. [self.navigationController pushViewController:equalRate animated:YES];
  139. }
  140. }
  141. #pragma mark -----------------KXTeachCycleViewDelegate-----------
  142. -(void)clickScrollViewItemWithIndex:(NSInteger)index
  143. {
  144. NSDictionary *dic=self.bannnerArray[index];
  145. KXNewsWebViewController *web=[[KXNewsWebViewController alloc]init];
  146. web.webID=dic[@"id"];
  147. [self.navigationController pushViewController:web animated:YES];
  148. }
  149. -(NSMutableArray *)bannnerArray
  150. {
  151. if (!_bannnerArray) {
  152. _bannnerArray=[[NSMutableArray alloc]init];
  153. }
  154. return _bannnerArray;
  155. }
  156. - (NSMutableArray *)dataSource
  157. {
  158. if (!_dataSource) {
  159. _dataSource = [[NSMutableArray alloc]init];
  160. }
  161. return _dataSource;
  162. }
  163. - (NSArray *)titleArr {
  164. if (!_titleArr) {
  165. _titleArr = @[@"房贷计算器",@"车贷计算器",@"信用卡分期计算器",@"个税计算器",@"等额本金计算器",@"等额本息计算器"];
  166. }
  167. return _titleArr;
  168. }
  169. - (NSArray *)imageAarr {
  170. if (!_imageAarr) {
  171. _imageAarr = @[@"house_calculate",@"car_calculate",@"card_calculate",@"person_calculate",@"equal_money",@"equal_rate"];
  172. }
  173. return _imageAarr;
  174. }
  175. - (void)didReceiveMemoryWarning {
  176. [super didReceiveMemoryWarning];
  177. // Dispose of any resources that can be recreated.
  178. }
  179. /*
  180. #pragma mark - Navigation
  181. // In a storyboard-based application, you will often want to do a little preparation before navigation
  182. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  183. // Get the new view controller using [segue destinationViewController].
  184. // Pass the selected object to the new view controller.
  185. }
  186. */
  187. @end