#import "oneViewController.h"
@interface oneViewController ()<UITableViewDelegate,UITableViewDataSource>
{
UITableView *tbv;
UIScrollView *scro;
UIPageControl *pag;
NSTimer *timer;
int k;
UIRefreshControl *refC;
}
@end
@implementation oneViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"aa"] style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bb"] style:UIBarButtonItemStylePlain target:self action:nil];
self.navigationItem.title = @"贝店";
tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
tbv.dataSource = self;
tbv.delegate=self;
// 初始化刷新控件
refC = [[UIRefreshControl alloc]init];
// 刷新提示文字
refC.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新.."];
// 添加事件
[refC addTarget:self action:@selector(abc) forControlEvents:UIControlEventValueChanged];
refC.tintColor = [UIColor whiteColor];
refC.backgroundColor = [UIColor redColor];
// 设置表格刷新控件
tbv.refreshControl = refC;
[self.view addSubview:tbv];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"2"];
if(!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"2"];
}
tbv.rowHeight=50;
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(5,0,70,50)];
label.text=@"今日特卖";
label.textColor= [UIColor redColor];
[cell addSubview:label];
UILabel *label2 = [[UILabelalloc]initWithFrame:CGRectMake(90,0,40,50)];
label2.text=@"居家";
[cell addSubview:label2];
UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(145,0,40,50)];
label3.text=@"居家";
[cell addSubview:label3];
UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(200,0,40,50)];
label4.text=@"居家";
[cell addSubview:label4];
UILabel *label5 = [[UILabel alloc]initWithFrame:CGRectMake(250,0,40,50)];
label5.text=@"居家";
[cell addSubview:label5];
UILabel *label6 = [[UILabel alloc]initWithFrame:CGRectMake(300,0,40,50)];
label6.text=@"居家";
[cell addSubview:label6];
// 初始化滚动式图
scro = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 200)];
// 设置滚动范围
scro.contentSize = CGSizeMake(3 * self.view.frame.size.width, 0);
// 禁用弹簧效果
scro.bounces=NO;
// 禁用水平滚动
scro.showsHorizontalScrollIndicator = NO;
// 设置整页滚动
scro.pagingEnabled = YES;
// 设置代理
scro.delegate=self;
// 设置滚动图片
for(inti =0; i <3; i++){
// 设置图片数组
NSArray *arr =@[@"1",@"2",@"3"];
UIImageView *imgV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.frame.size.width, 0, self.view.frame.size.width, 200)];
// 加载图片
imgV.image= [UIImage imageNamed:arr[i]];
// 添加到滚动视图中
[scro addSubview:imgV];
}
// 添加到cell中
[cell addSubview:scro];
// 设置豆豆
pag = [[UIPageControl alloc]initWithFrame:CGRectMake(90, 95, 150, 25)];
// 设置豆豆的数量
pag.numberOfPages = 3;
// 设置豆豆的颜色
pag.currentPageIndicatorTintColor = [UIColor orangeColor];
pag.pageIndicatorTintColor = [UIColor whiteColor];
// 添加到单元格中
[cell addSubview:pag];
// 创建定时器
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(aaa) userInfo:nil repeats:YES];
returncell;
}
// 滚动视图
- (void)scrollViewDidScroll:(UIScrollView*)scrollView{
// NSLog(@"%lf",scro.contentOffset.x);
pag.currentPage = scro.contentOffset.x/self.view.frame.size.width;
}
// 定时器
-(void)aaa{
[scro setContentOffset:CGPointMake(k * self.view.frame.size.width, 0)];
k++;
if(k>2){
k=0;
}
}
-(void)abc{
refC.attributedTitle = [[NSAttributedString alloc]initWithString:@"正在刷新中...."];
[self performSelector:@selector(bcd) withObject:nil afterDelay:3.0];
}
-(void)bcd{
[refC endRefreshing];
[tbv reloadData];
refC.attributedTitle = [[NSAttributedString alloc]initWithString:@"下拉刷新.."];
}
@end
网友评论