123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //
- // KDPSupplyGoodViewController.m
- // KuDianProject
- //
- // Created by admin on 2019/7/4.
- // Copyright © 2019 KDP. All rights reserved.
- //
- #import "KDPSupplyGoodViewController.h"
- #import "XLPageViewController.h"
- #import "XLPageViewControllerConfig.h"
- #import "KDPSupplyContentViewController.h"
- #import "KDPSearchViewController.h"
- #import "KDPClassModel.h"
- @interface KDPSupplyGoodViewController ()<XLPageViewControllerDelegate,XLPageViewControllerDataSrouce>
- @property (nonatomic, strong) XLPageViewController *pageVC;
- @property (nonatomic, strong) NSMutableArray *classArray;
- @property (nonatomic, strong) UIImageView *topBackImageView;
- @end
- @implementation KDPSupplyGoodViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self setUpTopView];
- self.view.backgroundColor = [UIColor colorWithRGB:0xf4f4f4];
- [self requestTopListData];
- }
- #pragma event handle
- - (void)requestTopListData{
- NSString *classUrl = [NSString stringWithFormat:@"%@api/goods/listTopBar",KDURL];
- [LoadingView showInView:self.view];
- [self.classArray removeAllObjects];
- [KDPNetworkRequestHTTP postURL:classUrl params:nil success:^(id _Nonnull json) {
- [LoadingView dismiss];
- NSArray *classArr = [NSArray yy_modelArrayWithClass:[KDPClassModel class] json:json[@"list"]];
- [self.classArray addObjectsFromArray:classArr];
- [self setUpPageVc];
- } failure:^(NSError * _Nonnull error) {
- [LoadingView dismiss];
- }];
- }
- - (void)setUpPageVc{
- XLPageViewControllerConfig *config = [[XLPageViewControllerConfig alloc] init];
- //标题间距
- config.titleSpace = 25;
- config.titleViewStyle = XLPageTitleViewStyleBasic;
- //标题高度
- config.titleViewHeight = 40;
- //标题选中颜色
- config.titleSelectedColor = [UIColor whiteColor];
- //标题选中字体
- config.titleSelectedFont = [UIFont fontWithName:@"PingFang-SC-Medium" size: 17];
- //标题正常颜色
- config.titleNormalColor = [UIColor whiteColor];
- //标题正常字体
- config.titleNormalFont = [UIFont fontWithName:@"PingFang-SC-Medium" size: 14];
- config.titleViewInset = UIEdgeInsetsMake(0, 10, 0, 10);
- //阴影颜色
- config.shadowLineColor = [UIColor whiteColor];
- //阴影宽度
- config.shadowLineWidth = 24;
- //阴影末端是直角
- config.shadowLineCap = XLPageShadowLineCapSquare;
- //分割线颜色
- config.separatorLineHidden = YES;
- config.shadowLineHeight = 3;
- config.shadowLineAnimationType = XLPageShadowLineAnimationTypeZoom;
-
- self.pageVC = [[XLPageViewController alloc] initWithConfig:config];
- self.pageVC.view.bounds = CGRectMake(0, KDStatusHeight + 58, SCREEN_WIDTH, SCREEN_HEIGHT-KDTabBarHeight-KDStatusHeight-58);
- self.pageVC.delegate = self;
- self.pageVC.dataSource = self;
- [self addChildViewController:self.pageVC];
- [self.view addSubview:self.pageVC.view];
- }
- - (void)searchBtnClick:(UIButton *)sender{
- KDPSearchViewController *searchVC = [[KDPSearchViewController alloc] init];
- [self.navigationController pushViewController:searchVC animated:NO];
- }
- - (void)setUpTopView{
- self.navBar.hidden = YES;
- NSInteger height = KDNavBarHeight == 64 ? 135 : 163;
- UIView *topBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, height)];
- [topBackView setGradientBackgroundWithColors:@[[UIColor colorWithRGB:0xFF235F],[UIColor colorWithRGB:0xFF7676]] locations:@[@0,@1] startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
- [self.view addSubview:topBackView];
-
- UIImageView *imageView = [[UIImageView alloc] initWithFrame:topBackView.bounds];
- [self.view addSubview:imageView];
- imageView.hidden = YES;
- self.topBackImageView = imageView;
-
- // search
- UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- searchBtn.frame = CGRectMake(15, KDStatusHeight + 7, SCREEN_WIDTH - 30, 31);
- searchBtn.backgroundColor = [UIColor whiteColor];
- [searchBtn setImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];
- [searchBtn setTitle:@"搜索你想要的商品" forState:UIControlStateNormal];
- [searchBtn setTitleColor:[UIColor colorWithRGB:0x8E8D8D] forState:UIControlStateNormal];
- searchBtn.titleLabel.font = FONT_SYS(14);
- searchBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
- searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
- searchBtn.layer.cornerRadius = 15.5;
- searchBtn.layer.masksToBounds = YES;
- searchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
- [searchBtn addTarget:self action:@selector(searchBtnClick:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:searchBtn];
-
- }
- - (NSMutableArray *)classArray{
- if (!_classArray) {
- _classArray = [NSMutableArray array];
- }
- return _classArray;
- }
- #pragma mark - XLPageViewController datasource and delegate
- - (NSInteger)pageViewControllerNumberOfPage{
- return self.classArray.count;
- }
- - (NSString *)pageViewController:(XLPageViewController *)pageViewController titleForIndex:(NSInteger)index{
- KDPClassModel *model = self.classArray[index];
- return model.name;
- }
- - (void)pageViewController:(XLPageViewController *)pageViewController didSelectedAtIndex:(NSInteger)index{
- KDPClassModel *classModel = self.classArray[index];
- if (classModel.backimg.length) {
- self.topBackImageView.hidden = NO;
- [self.topBackImageView sd_setImageWithURL:[NSURL URLWithString:classModel.backimg]placeholderImage:[UIImage imageNamed:placholderImg]];
- } else{
- self.topBackImageView.hidden = YES;
- }
- NSLog(@"%ld",index);
- }
- - (UIViewController *)pageViewController:(XLPageViewController *)pageViewController viewControllerForIndex:(NSInteger)index{
- KDPSupplyContentViewController *contentVC = [[KDPSupplyContentViewController alloc] init];
- contentVC.classModel = self.classArray[index];
- return contentVC;
- }
- @end
|