//
// ViewController.m
// Tab bar controllre
//
// Created by 红珊瑚 on 15/5/21.
// Copyright (c) 2015年 红珊瑚. All rights reserved.
//
#import "ViewController.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#define kbuttonArray @"buttonArray"
#define ktitle1 @"title1"
#define ktitle2 @"title2"
#define ktitle3 @"title3"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSArray *buttonArray;
NSArray *array1;
UITableView *tableview1;
UIScrollView *scroll;
UIScrollView *scroll1;
UIScrollView *scroll2;
UIScrollView *scroll3;
UIButton *button1;
UIButton *button2;
UIButton *button3;
UIButton *button4;
UIButton *button5;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
self.navigationItem.title =@"奢侈品网购平台";
tableview1 = [[UITableViewalloc]initWithFrame:CGRectMake(0,0,320,568)];
tableview1.backgroundColor = [UIColorlightGrayColor];
tableview1.delegate =self;
tableview1.dataSource =self;
[self.viewaddSubview:tableview1];
//前五个按钮
button1 = [[UIButtonalloc]initWithFrame:CGRectMake(2,0,156,206)];
button1.backgroundColor = [UIColorredColor];
[button1sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579346_230297.jpg"]
forState:UIControlStateNormal];
button2 = [[UIButtonalloc]initWithFrame:CGRectMake(2,208,156,102)];
button2.backgroundColor = [UIColororangeColor];
[button2sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://120.27.31.49:8080/lehuo/upload/image/pa2015052116525397610.jpg"]
forState:UIControlStateNormal];
button3 = [[UIButtonalloc]initWithFrame:CGRectMake(161,0,157,102)];
button3.backgroundColor = [UIColororangeColor];
[button3sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_11/704_1575574_236134.jpg"]
forState:UIControlStateNormal];
button4 = [[UIButtonalloc]initWithFrame:CGRectMake(161,104,157,102)];
button4.backgroundColor = [UIColorredColor];
[button4sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_11/704_1575788_139912.jpg"]
forState:UIControlStateNormal];
button5 = [[UIButtonalloc]initWithFrame:CGRectMake(161,208,157,102)];
button5.backgroundColor = [UIColorredColor];
[button5sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_11/704_1575760_470154.jpg"]
forState:UIControlStateNormal];
//buttonArray = [[NSArray alloc] initWithObjects:button1,button2,button3,button4,button5, nil];
/*
array1 = @[
@{
ktitle1:@"新品上架",
},
@{
ktitle2:@"热销",
},
@{
ktitle3:@"本周新店"
}
];
*/
//左右滑动的地方
scroll = [[UIScrollViewalloc]initWithFrame:CGRectMake(2,2,318,217)];
scroll.pagingEnabled=YES;
scroll.backgroundColor = [UIColorwhiteColor];
scroll1 = [[UIScrollViewalloc]initWithFrame:CGRectMake(2,2,316,217)];
scroll1.backgroundColor = [UIColorwhiteColor];
scroll2 = [[UIScrollViewalloc]initWithFrame:CGRectMake(2,2,316,217)];
scroll2.backgroundColor = [UIColorwhiteColor];
scroll3 = [[UIScrollViewalloc]initWithFrame:CGRectMake(2,2,316,217)];
scroll3.backgroundColor = [UIColorwhiteColor];
// //标头
// UILabel *labelA = [[UILabel alloc] initWithFrame:CGRectMake(100, 18, 120, 31)];
// labelA.text = @"奢侈品网购平台";
// [self.view addSubview:labelA];
}
//改变cell间距
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.section)
{
case0:
if (indexPath.row ==1)
{
return310;
}elseif (indexPath.row ==0)
{
return221;
}
break;
case1:
if (indexPath.row ==0)
{
return30;
}elseif (indexPath.row ==1)
{
return221;
}
break;
case2:
if (indexPath.row ==0)
{
return30;
}elseif (indexPath.row ==1)
{
return221;
}
break;
case3:
if (indexPath.row ==0)
{
return30;
}elseif (indexPath.row ==1)
{
return221;
}
break;
}
return40;
}
//共四组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return4;
}
//每组两个
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return2;
}
//显示每个cell的内容
-(UITableViewCell *)tableView:(UITableViewCell *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil];
switch (indexPath.section)
{
case0:
{
if (indexPath.row ==1)
{
/*
//按钮数组的路径
NSDictionary *dictionary = array1[indexPath.section];
NSArray *buttonArray2 = dictionary[kbuttonArray];
NSArray *text = buttonArray2[indexPath.row];
*/
[celladdSubview:button1];
[celladdSubview:button2];
[celladdSubview:button3];
[celladdSubview:button4];
[celladdSubview:button5];
}elseif (indexPath.row ==0)
{
for (int i =0; i <4; i++)
{
UIButton *button6 = [[UIButtonalloc]initWithFrame:CGRectMake(i*318,0,317,217)];
button6.backgroundColor = [UIColorblueColor];
[celladdSubview:scroll];
scroll.contentSize =CGSizeMake((i+1)*318,217);
[scrolladdSubview:button6];
//[button6 setTitle:[NSString stringWithFormat:@"%d",i+1] forState:UIControlStateNormal];
button6.tag = i+1;
if (button6.tag ==1)
{
[button6 sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_12/704_1579273_974059.jpg"]
forState:UIControlStateNormal];
}elseif (button6.tag ==2)
{
[button6 sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_11/704_1575541_173559.gif"]
forState:UIControlStateNormal];
}elseif (button6.tag ==3)
{
[button6 sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_11/704_1575533_435177.gif"]
forState:UIControlStateNormal];
}elseif (button6.tag ==4)
{
[button6 sd_setBackgroundImageWithURL:[NSURLURLWithString:@"http://www.sinaimg.cn/dy/slidenews/4_img/2015_11/704_1575571_948836.jpg"]
forState:UIControlStateNormal];
}
}
}
}
break;
case1:
{
if (indexPath.row ==0)
{
UIButton *button7 = [[UIButtonalloc]initWithFrame:CGRectMake(250,2,66,28)];
button7.backgroundColor = [UIColorlightGrayColor];
[celladdSubview:button7];
[button7 setTitle:[NSStringstringWithFormat:@"更多》"]forState:UIControlStateNormal];
cell.textLabel.text = [NSStringstringWithFormat:@"新品上架"];
}elseif (indexPath.row ==1)
{
for (int i =0; i <20; i++)
{
UIButton *button8 = [[UIButtonalloc]initWithFrame:CGRectMake(i*130,10,100,200)];
button8.backgroundColor = [UIColorredColor];
[celladdSubview:scroll1];
scroll1.contentSize =CGSizeMake(i*136,200);
[scroll1addSubview:button8];
[button8 setTitle:[NSStringstringWithFormat:@"%d",i+1]forState:UIControlStateNormal];
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(30,120,260,30)];
label.text =@"钻石";
[button8addSubview:label];
}
}
}
break;
case2:
{
if (indexPath.row ==0)
{
UIButton *button9 = [[UIButtonalloc]initWithFrame:CGRectMake(250,2,66,28)];
button9.backgroundColor = [UIColorlightGrayColor];
[celladdSubview:button9];
[button9 setTitle:[NSStringstringWithFormat:@"更多》"]forState:UIControlStateNormal];
cell.textLabel.text = [NSStringstringWithFormat:@"热销"];
}elseif (indexPath.row ==1)
{
for (int i =0; i <20; i++)
{
UIButton *button10 = [[UIButtonalloc]initWithFrame:CGRectMake(i*130,10,100,200)];
button10.backgroundColor = [UIColorpurpleColor];
[celladdSubview:scroll2];
scroll2.contentSize =CGSizeMake(i*136,200);
[scroll2addSubview:button10];
[button10 setTitle:[NSStringstringWithFormat:@"%d",i+1]forState:UIControlStateNormal];
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(30,120,260,30)];
label.text =@"法国红酒";
[button10addSubview:label];
}
}
}
break;
case3:
{
if (indexPath.row ==0)
{
UIButton *button11 = [[UIButtonalloc]initWithFrame:CGRectMake(250,2,66,28)];
button11.backgroundColor = [UIColorlightGrayColor];
[celladdSubview:button11];
[button11 setTitle:[NSStringstringWithFormat:@"更多》"]forState:UIControlStateNormal];
cell.textLabel.text = [NSStringstringWithFormat:@"本周新店"];
}elseif (indexPath.row ==1)
{
for (int i =0; i <20; i++)
{
UIButton *button12= [[UIButtonalloc]initWithFrame:CGRectMake(i*130,10,100,200)];
button12.backgroundColor = [UIColororangeColor];
[celladdSubview:scroll3];
scroll3.contentSize =CGSizeMake(i*136,200);
[scroll3addSubview:button12];
[button12 setTitle:[NSStringstringWithFormat:@"%d",i+1]forState:UIControlStateNormal];
button12.tag = i+1;
UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(30,120,260,30)];
label.text =@"碧桂园";
[button12addSubview:label];
}
}
}
break;
}
return cell;
//BOOL ii= [self dbhyuvbin:nil arr:nil]; //自定义方法 (部分)
}
//-(BOOL)dbhyuvbin: (NSString *)str arr:(NSArray*)arr //自定义方法 (部分)
//{
//
// return YES;
//}
@end