万家灯火

#import “ShouyeViewController.h”

 #define HCWidth self.view.frame.size.width
 #define HCHeight self.view.frame.size.height
 @interface ShouyeViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
 {
 
 UIScrollView *sc; // 滚动视图
 UIPageControl *pageC; // 分页控制符
 NSArray *imgArr; // 图l片数组
 NSTimer *timer; // 定时器
 int k; // 计数
 UIImageView *imgV;

 }
 
 @property(nonatomic,strong)UITableView *tbv;
 
 @end
 
 @implementation ShouyeViewController
 
 (void)viewDidLoad {
 [super viewDidLoad];
 
 self.title = @“万家灯火”;
 self.navigationController.navigationBar.titleTextAttributes=
 @{NSForegroundColorAttributeName:[UIColor whiteColor],
 NSFontAttributeName:[UIFont systemFontOfSize:22]};
 self.navigationController.navigationBar.barTintColor = [UIColor redColor];
 [self.view addSubview:self.tbv];
 }
 
 -(UITableView *)tbv{
 if (!_tbv)
 {
 _tbv=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStyleGrouped];
 }
 _tbv.delegate=self;
 _tbv.dataSource=self;
 return _tbv;
 
 }
 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
 return 3;
 }
 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 if (section0)
 {
 return 1;
 }else if (section1){
 return 1;
 }else{
 return 3;
 }
 }
 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath )indexPath{
 static NSStringstr=@“str”;
 UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:str];
 if (!cell)
 {
 cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:str];
 }
 
 if (indexPath.section==0)
 {
 self.tbv.rowHeight=250;
 //初始化定时器
 timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(qqq) userInfo:nil repeats:YES];
 // 定时器开启
 [timer fire];
 
 
 // 滚动视图
 sc = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, HCWidth, 250)];
 // 设置滚动视图的代理
 sc.delegate = self;
 // 滚动范围
 sc.contentSize = CGSizeMake(4 * HCWidth,250);
 // 分页
 sc.pagingEnabled = YES;
 // 弹簧
 sc.bounces = NO;
 // 禁用水平滚动条
 sc.showsHorizontalScrollIndicator = NO;
 // 将滚动视图添加
 [self.view addSubview:sc];
 
 // 添加图片
 for (int i = 0; i < 4; i++){
 
 imgArr = @[@"14",@"15",@"16",@"17"];
 // 图片
 imgV = [[UIImageView alloc]initWithFrame:CGRectMake(i*HCWidth, 0, HCWidth, 250)];
 imgV.image = [UIImage imageNamed:imgArr[i]];
 
 // 设置用户交互属性
 imgV.userInteractionEnabled = YES;
 // 滚动视图添加图片
 [sc addSubview:imgV];
 
 }
 [cell addSubview:sc];
 }else if (indexPath.section==1){
 
 self.tbv.rowHeight=100;
 NSArray *arr=@[@"1",@"2",@"3",@"4"];
 NSArray *arr1=@[@"保险精品",@"课程精品",@"车险定制",@"关于我们"];
 
 for (int i=0; i<arr.count; i++)
 {
 UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(15+100*i,10, 70, 70)];
 [btn setBackgroundImage:[UIImage imageNamed:arr[i]] forState:UIControlStateNormal];
 [cell addSubview:btn];
 UILabel *l1 = [[UILabel alloc]initWithFrame:CGRectMake(15 + 100*i, 80, 70, 20)];
 [l1 setText:arr1[i]];
 [cell addSubview:l1];
 }
 
 }
 else{
 self.tbv.rowHeight=150;
 NSArray *arr=@[@"aaaa",@"bbbb",@"cccc"];
 if (indexPath.row == 0) {
 _tbv.rowHeight = 30;
 cell.textLabel.text = @"| 热销产品";
 cell.textLabel.textColor=[UIColor orangeColor];
 }else{
 _tbv.rowHeight = 150;
 UIImageView *im = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 150)];
 im.image = [UIImage imageNamed:arr[indexPath.row]];
 [cell addSubview:im];
 }
 
 }
 return cell;

 }
 
 // 视图已经滚动的方法
 -(void)scrollViewDidScroll:(UIScrollView *)scrollView{
 
 pageC.currentPage = sc.contentOffset.x/HCWidth;
 
 NSLog(@"%lf",sc.contentOffset.x);

 }
 // 定时器 (1s -> 进入一次)
 -(void)qqq{
 
 NSLog(@"%d",k);
 // set 方法 -> 设置 滚动视图的偏移量
 [sc setContentOffset:CGPointMake(k *HCWidth, 0)];
 k++;
 if(k > 3){
 // 定时器停止
 //        [timer invalidate];
 //        // 禁止滚动
 //        sc.scrollEnabled =NO;
 k=0;
 }
 }
 
 @end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值