123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- //
- // KXNewTeachViewController.m
- // CAISHEN
- //
- // Created by 小花 on 2017/11/8.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXNewTeachViewController.h"
- #import "KXTeachCycleView.h"
- #import "KXTeachCollectionViewCell.h"
- #import "KXNewsWebViewController.h"
- #import "KXNewTeachCollectionViewCell.h"
- #import "KXHouseCalculateViewController.h"
- #import "KXEqualRateToolViewController.h"
- #import "KXIndividualIncomeViewController.h"
- #import "KXInstallmentViewController.h"
- #import "KXCarLoancalViewController.h"
- @interface KXNewTeachViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,KXTeachCycleViewDelegate>
- @property (nonatomic,strong)KXTeachCycleView *teachCycle;
- @property (nonatomic,strong)UICollectionView *collectionView;
- @property (nonatomic,strong)NSMutableArray *bannnerArray;
- @property (nonatomic,strong)NSMutableArray *dataSource;
- @property (nonatomic, strong) NSArray *titleArr;
- @property (nonatomic, strong) NSArray *imageAarr;
- @end
- @implementation KXNewTeachViewController
- {
- UIView *headerView;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.view.backgroundColor = [UIColor whiteColor];
- [self createCollectionView];
- [self requestDataSource];
- }
- - (void)createCollectionView
- {
- self.name = @"工具";
- headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 250)];
- headerView.backgroundColor = [UIColor whiteColor];
-
- UILabel *teachLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
- teachLabel.text = @"";
- teachLabel.textColor = [UIColor titleColor];
- teachLabel.font = FONT_SYS(16);
- teachLabel.textAlignment = NSTextAlignmentLeft;
- [headerView addSubview:teachLabel];
-
- self.teachCycle = [[KXTeachCycleView alloc]initWithFrame:CGRectMake(0, 30, SCREEN_WIDTH - 15, 160)];
- self.teachCycle.delegate = self;
- [headerView addSubview:self.teachCycle];
-
- UILabel *grayLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 210, SCREEN_WIDTH, 5)];
- grayLabel.backgroundColor = [UIColor colorWithWhite:0 alpha:0.05];
- [headerView addSubview:grayLabel];
-
- UILabel *programLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 220, 100, 20)];
- programLabel.text = @"理财工具";
- programLabel.textColor = [UIColor titleColor];
- programLabel.font = FONT_SYS(16);
- programLabel.textAlignment = NSTextAlignmentLeft;
- [headerView addSubview:programLabel];
- UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
- flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH-1)/2, Fitsize(122));
- flowLayout.minimumLineSpacing = 1;
- flowLayout.minimumInteritemSpacing = 1;
- flowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 250);
- self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - NavHeight - TabbarHeight) collectionViewLayout:flowLayout]; [self.collectionView registerClass:[KXNewTeachCollectionViewCell class] forCellWithReuseIdentifier:@"newTeach"];
- self.collectionView.backgroundColor = [UIColor KXColorWithHex:0xeeeeed];
- self.collectionView.delegate = self;
- self.collectionView.dataSource = self;
- [self.view addSubview: self.collectionView];
- [self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"UICollectionViewHeader"];
- }
- #pragma mark 请求数据
- -(void)requestDataSource
- {
- NSString *urlString=[NSString stringWithFormat:@"%@/information/getinformationsbypackage",URL];
- NSDictionary *paraDict=@{@"package_id":@"package_1",@"classification_id":@"贷款",@"page":@(1)};
-
- [KXHTTP post:urlString params:paraDict success:^(id json) {
-
- NSMutableArray *bannerImageArray=[NSMutableArray arrayWithCapacity:0];
- if (self.bannnerArray.count==0) {
- for (NSDictionary *dict in json[@"ios_teach_banner"]) {
- [self.bannnerArray addObject:dict];
- [bannerImageArray addObject:dict[@"thumbnail"]];
- }
- _teachCycle.cycleArray=bannerImageArray;
- }
-
- NSArray *array=[NSArray yy_modelArrayWithClass:[KXNewsModel class] json:[json[@"listdata"] valueForKey:@"data"]];
-
- for (KXNewsModel *model in array) {
- [self.dataSource addObject:model];
- }
-
- [self.collectionView reloadData];
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.titleArr.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- KXNewTeachCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newTeach" forIndexPath:indexPath];
-
- [cell setTitle:self.titleArr[indexPath.row] andImage:self.imageAarr[indexPath.row]];
- return cell;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- {
-
- NSString *CellIdentifier = @"UICollectionViewHeader";
- //从缓存中获取 Headercell
- UICollectionReusableView *cell = (UICollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:CellIdentifier forIndexPath:indexPath];
- [cell addSubview:headerView];
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (indexPath.item == 0) {
- KXHouseCalculateViewController *houseCalcul = [[KXHouseCalculateViewController alloc] init];
- [self.navigationController pushViewController:houseCalcul animated:YES];
- }
-
- if (indexPath.item == 1) {
- KXCarLoancalViewController *carloanVC = [[KXCarLoancalViewController alloc]init];
- [self.navigationController pushViewController:carloanVC animated:YES];
- }
-
- if (indexPath.item == 2) {
- KXInstallmentViewController *vc = [[KXInstallmentViewController alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- }
-
- if (indexPath.item == 3) {
- KXIndividualIncomeViewController *vc = [[KXIndividualIncomeViewController alloc] init];
- [self.navigationController pushViewController:vc animated:YES];
- }
-
-
- if (indexPath.item == 4) {
- KXEqualRateToolViewController *equRateTool = [[KXEqualRateToolViewController alloc] init];
- equRateTool.equalType = EqualMoneyType;
- [self.navigationController pushViewController:equRateTool animated:YES];
- }
-
- if (indexPath.item == 5) {
- KXEqualRateToolViewController *equalRate = [[KXEqualRateToolViewController alloc] init];
- equalRate.equalType = EqualRateType;
- [self.navigationController pushViewController:equalRate animated:YES];
- }
- }
- #pragma mark -----------------KXTeachCycleViewDelegate-----------
- -(void)clickScrollViewItemWithIndex:(NSInteger)index
- {
- NSDictionary *dic=self.bannnerArray[index];
-
- KXNewsWebViewController *web=[[KXNewsWebViewController alloc]init];
-
- web.webID=dic[@"id"];
-
- [self.navigationController pushViewController:web animated:YES];
-
- }
- -(NSMutableArray *)bannnerArray
- {
- if (!_bannnerArray) {
- _bannnerArray=[[NSMutableArray alloc]init];
- }
- return _bannnerArray;
- }
- - (NSMutableArray *)dataSource
- {
- if (!_dataSource) {
- _dataSource = [[NSMutableArray alloc]init];
- }
- return _dataSource;
- }
- - (NSArray *)titleArr {
- if (!_titleArr) {
- _titleArr = @[@"房贷计算器",@"车贷计算器",@"信用卡分期计算器",@"个税计算器",@"等额本金计算器",@"等额本息计算器"];
- }
- return _titleArr;
- }
- - (NSArray *)imageAarr {
- if (!_imageAarr) {
- _imageAarr = @[@"house_calculate",@"car_calculate",@"card_calculate",@"person_calculate",@"equal_money",@"equal_rate"];
- }
- return _imageAarr;
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|