123HHD

NSArray *lableArr = @[@"汉堡薯条",@"包子粥店",@"鲜花蛋糕",@"麻辣烫",@"地方菜",@"披萨意面",@"异国料理"];
NSArray *imgArr = @[@"1.png",@"2.png",@"3.png",@"4.png",@"5.png",@"6.png",@"7.png"];
for (int i = 0; i

                NSInteger index = i % 4;
                NSInteger page = i / 4;
                
                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
                btn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                btn.titleLabel.font = [UIFont systemFontOfSize:14];
                [btn setTitle:lableArr[i] forState:UIControlStateNormal];
                [btn setImage:[UIImage imageNamed:imgArr[i]] forState:UIControlStateNormal];
                [btn addTarget:self action:@selector(btn_click:) forControlEvents:UIControlEventTouchUpInside];
                [self initButton:btn];
                
                [cell addSubview:btn];
            }

            [myScrollView addSubview:view];
        }
        
        myScrollView.bounces = NO;
        
        myScrollView.pagingEnabled = YES;
        
        myScrollView.showsHorizontalScrollIndicator = NO;
        
        myScrollView.contentSize = CGSizeMake(WIDTH * 2, HEIGHT);
        
        myScrollView.delegate = self;
        
        [cell addSubview:myScrollView];
        pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(WIDTH /3, 170, WIDTH / 3, 40)];
        
        // 设置页数
        pageControl.numberOfPages = 2;
        // 设置页码的点的颜色
        pageControl.pageIndicatorTintColor = [UIColor yellowColor];
        // 设置当前页码的点颜色
        pageControl.currentPageIndicatorTintColor = [UIColor redColor];
        [cell addSubview:pageControl];
        
    }else if (indexPath.row == 1){
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
        img.image = [UIImage imageNamed:@"grass.png"];
        [cell addSubview:img];
    }
    
}else if (indexPath.section == 1){
    
    // 标题
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 50)];
    label.text = @"四星快餐";
    label.font = [UIFont systemFontOfSize:20 weight:1];
    [cell addSubview:label];
   
    // 图片
    UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 4 + 20, 10, 50, 50)];
    img.image = [UIImage imageNamed:@"5.png"];
    
    [cell addSubview:img];
    
    // 标题
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2 + 10, 10, 100, 50)];
    label1.text = @"霸王餐";
    label1.font = [UIFont systemFontOfSize:20 weight:1];
    [cell addSubview:label1];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 2, 0, 2, 80)];
    line.backgroundColor = [UIColor colorWithRed:(237 / 255.0) green:(237 / 255.0) blue:(237 / 255.0) alpha:1.0];
    [cell addSubview:line];
    
    // 图片
    UIImageView *img1 = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width / 4 * 3 + 20, 10, 50, 50)];
    img1.image = [UIImage imageNamed:@"2.png"];
    
    [cell addSubview:img1];
    
}else if (indexPath.section == 2){
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5, 10, 400, 30)];
    label.text = @"限时抢购   距离结束 00:31:00";
    label.font = [UIFont systemFontOfSize:18 weight:1];
    [cell addSubview:label];
    
    float x = 10;
    float y = 40;
    float w = 100;
    float h = 115;
    
    for (int i = 0; i<4; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setFrame:CGRectMake(w*i+x, y, w, h)];
        NSArray *lablelArr = @[@"扁豆焖面",@"驴肉火烧",@"黄焖鸡米饭",@"莫利炖鱼"];
        [btn setTitle:lablelArr[i] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"5"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        [btn addTarget:self action:@selector(btn_click:) forControlEvents:UIControlEventTouchUpInside];
        [self initButton:btn];
        [cell addSubview:btn];
    }
}
return cell;

}
-(void)btn_click:(UIButton *)btn{
NSLog(@"点击按钮");
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

//求余
NSInteger index = scrollView.contentOffset.x / scrollView.frame.size.width;

pageControl.currentPage = index;

}

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

CGFloat cellHight = 0.0;

NSInteger sect = indexPath.section;

NSInteger row = indexPath.row;

switch (sect) {
        
    case 0:
        
        switch (row) {
                
            case 0:
                
                cellHight = 200;
                
                break;
                
            case 1:
                
                cellHight = 100;
                
                break;
                
            default:
                
                break;
                
        }
        
        break;
        
    case 1:
        
        switch (row) {
                
            case 0:
                
                cellHight = 80;
                
                break;
                
            case 1:
                
                cellHight = 80;
                
                break;
                
            default:
                break;
                
        }
        break;
        
    case 2:
        
        cellHight = 180;
        
        break;
        
    default:
        
        break;
        
}

return cellHight;

}

  • (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{
return 0.1;

}

  • (void)viewWillAppear:(BOOL)animated

{

self.navigationController.navigationBarHidden = YES;

}

  • (void)dragMoving:(UIControl *)c withEvent:ev

{
c.center = [[[ev allTouches] anyObject] locationInView:self.view];
}

  • (void)dragEnded:(UIControl *)c withEvent:ev
    {
    c.center = [[[ev allTouches] anyObject] locationInView:self.view];
    }
    -(void)buttonAction:(UIButton *)sender
    {
    NSLog(@"点击购物车!");
    }

  • (UIStatusBarStyle)preferredStatusBarStyle{

    return UIStatusBarStyleLightContent;

}

你可能感兴趣的:(123HHD)