@interface OldCourseViewController ()
@property (nonatomic, strong) UIScrollView *navView;
@end
@implementation OldCourseViewController
{
NSArray*_sectionTitles;
NSMutableArray*_adList;
NSArray*_iconList;
UIView*_headView;
}
static NSString *cellIdentifier = @"CourceNewListCell";
// 顶部分类icon
- (void)actionsClick:(UIButton*)btn {
if(btn.tag==22222) {
NSString *book_store = [[NSUserDefaults standardUserDefaults] objectForKey:@"shopUrl"];
PTVWebViewController*webV = [[PTVWebViewController alloc] init];
webV.url = book_store;
webV.titleString =@"书店";
[self.navigationController pushViewController:webV animated:YES];
}else{
CourseMoreListController *listC = [[CourseMoreListController alloc] init];
NewsCat *bean = [_schoolUtils getCatInfo:(int)btn.tag];
// 获取所有子类
NSMutableArray*catesArr = [_schoolUtils getCatList:(int)btn.tag hasAll:NO];
if(catesArr && catesArr.count>0) {
NewsCat *tempBean = [[NewsCat alloc] init];
tempBean.cid = (int)btn.tag;
tempBean.title =@"全部";
[catesArr insertObject:tempBean atIndex:0];
}
listC.cateType = (int)btn.tag;
listC.subCatesArr = catesArr;
listC.cateName = bean.title;
[self.navigationController pushViewController:listC animated:YES];
}
}
- (void)refreshNavData {
for(UIView *subVin_navView.subviews) {
[subV removeFromSuperview];
}
[_navView removeFromSuperview];
_navView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NAV_HEIGHT+BAR_HEIGHT,SCREEN_WIDTH,44)];
_navView.backgroundColor = [UIColor whiteColor];
_navView.showsHorizontalScrollIndicator =NO;
_navView.showsVerticalScrollIndicator =NO;
[self.view addSubview:_navView];
CGFloatw =15;
for(NSInteger i =0; i < _courseListData.count; i++) {
StoreBean *bean = _courseListData[i];
CGSize labelSize = [bean.title pp_sizeWithFont:[UIFont systemFontOfSize:16weight:UIFontWeightMedium]];
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = bean.title;
titleLabel.frame = CGRectMake(w,0, labelSize.width+20,44);
titleLabel.textAlignment = NSTextAlignmentLeft;
if(i ==self.tabSelect-100) {
titleLabel.font = [UIFont systemFontOfSize:16weight:UIFontWeightMedium];
titleLabel.textColor =UIColorFromRGB(UI_COLOR_Exam_Red);
}
else{
titleLabel.font = [UIFont systemFontOfSize:16weight:UIFontWeightMedium];
titleLabel.textColor =UIColorFromRGB(UI_COLOR_HINT);
}
titleLabel.tag =10000+i;
[_navView addSubview:titleLabel];
UIButton *navBtn = [UIButton buttonWithType:UIButtonTypeCustom];
navBtn.frame = CGRectMake(w,0, labelSize.width+20,44);
navBtn.titleLabel.font = [UIFont systemFontOfSize:16weight:UIFontWeightMedium];;
navBtn.tag =100+ i;
[navBtn addTarget:selfaction:@selector(navBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[_navView addSubview:navBtn];
w += labelSize.width+20;
}
_navView.contentSize = CGSizeMake(w,44);
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
}
- (void)navBtnClick:(UIButton*)btn {
UILabel*oldLabel = [_navView viewWithTag:self.tabSelect-100+10000];
UILabel*newLabel = [_navView viewWithTag:btn.tag-100+10000];
newLabel.textColor=UIColorFromRGB(UI_COLOR_Exam_Red);
oldLabel.textColor=UIColorFromRGB(UI_COLOR_HINT);
[_listView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0inSection:btn.tag -100] atScrollPosition:UITableViewScrollPositionTop animated:YES];
self.tabSelect = btn.tag;
[selfscroll:btn.tag-100];
}
- (void)scroll:(NSInteger)selectNum{
[UIView animateWithDuration:0.3 animations:^{
CGFloatx =15;
CGFloatbtnWidth =0;
for(NSIntegeri =0; i <= selectNum; i++) {
StoreBean *bean = _courseListData[i];
CGSizelabelSize = [bean.title pp_sizeWithFont:[UIFont systemFontOfSize:16weight:UIFontWeightMedium]];
if(i == selectNum) {
btnWidth = labelSize.width+20;
}
x += labelSize.width+20;
NSLog(@"%@",bean.title);
}
CGFloatw =self.navView.contentSize.width;//总长度
x = x-btnWidth*0.5-SCREEN_WIDTH/2.0;
CGFloatx1 = w -SCREEN_WIDTH;//可滚动长度
if(x1 <0) {//不可滚动
return;
}
x = x
if(x <0) {
x =0;
}
self.navView.contentOffset = CGPointMake(x,0);
}];
}
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollViewdidSelectItemAtIndex:(NSInteger)index
{
Slide*object =_adList[index];
[Utils slideClick:self slide:object];
/*
Slide *object = _adList[index];
if (object.linkUrl) {
[Utils openUri:_vc url:object.linkUrl];
}
*/
}
@end