//布局轮播图
- (void)layoutHeaderView
{
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * 0.6)];
self.tableView.tableHeaderView.backgroundColor = [UIColor orangeColor];
// 情景:采用网络图片实现
NSArray *imagesURLStrings= _strArray;
// 情景:图片配文字
NSArray *titles = _titleArray;
width = [UIScreen mainScreen].bounds.size.width;
//网络加载 --- 创建带标题的图片轮播器
SDCycleScrollView *cycleScrollView2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, width, self.tableView.tableHeaderView.frame.size.height) imageURLStringsGroup:nil]; // 模拟网络延时情景
cycleScrollView2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
cycleScrollView2.delegate = self;
cycleScrollView2.titlesGroup = titles;
cycleScrollView2.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
cycleScrollView2.placeholderImage = [UIImage imageNamed:@"left.png"];
[self.tableView.tableHeaderView addSubview:cycleScrollView2];
//--- 模拟加载延迟
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
cycleScrollView2.imageURLStringsGroup = imagesURLStrings;
});
}
//点击轮播图图片进入详情
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
HomeModel *model = self.homeModelArray[index];
DetailViewController *detailVC = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"detail"];
detailVC.myID = model.dishes_id;
detailVC.myTitle = model.title;
detailVC.homeModel = model;
[self.navigationController pushViewController:detailVC animated:YES];
}