- <div class="blockcode"><blockquote>//
- // TableController.m
- // hedaAssistant
- //
- // Created by bear on 15/11/28.
- // Copyright © 2015年 bear. All rights reserved.
- //
- #import "TableController.h"
- #import "TableCellController.h"
- #import "UINavigationItem+custom.h"
- //获取屏幕 宽度、高度
- #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
- #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
- //NavBar高度
- #define NavigationBar_HEIGHT 44
- #define StatusBar_HEIGHT 20
- #define TabBar_HEIGHT 49
- @interface TableController (){
- UIScrollView *tableScrowView;
- CGFloat dayWidth;
- CGFloat sectionHeight;
- }@end
- @implementation TableController
- -(void)viewDidLoad{
- [self setUI];
- }
- -(void)setUI{
- //设置 导航栏的背景
- [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tabbar_background.png"] forBarMetrics:UIBarMetricsDefault];
- //设置自己的标题x
- [self.navigationItem setMyTitle:@"考试安排表"];
- //添加整体背景
- UIImage *bgImg=[UIImage imageNamed:@"main.png"];
- UIImageView *mainBgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(StatusBar_HEIGHT+NavigationBar_HEIGHT+TabBar_HEIGHT))];
- mainBgView.image=bgImg;
- [self.view addSubview:mainBgView];
- //添加顶部星期背景
- UIView *headBg=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
- [headBg setAlpha:0.7f];
- headBg.backgroundColor=[UIColor orangeColor];
- [self.view addSubview:headBg];
- //定义基本宽高
- dayWidth=(CGFloat) (SCREEN_WIDTH-30)/5;
- sectionHeight=(CGFloat)(SCREEN_HEIGHT-(StatusBar_HEIGHT+NavigationBar_HEIGHT+TabBar_HEIGHT)-30)/8;
-
-
- #pragma mark 添加ScrowView能左右滚动
- tableScrowView=[[UIScrollView alloc]init];
- tableScrowView.frame=CGRectMake(0, 0, SCREEN_WIDTH,sectionHeight*8+35);
- tableScrowView.contentSize = CGSizeMake(dayWidth*7+30, 0);
- tableScrowView.bounces=NO;
- [self.view addSubview:tableScrowView];
-
- #pragma mark 添加星期头部
- int i;
- NSString *weektitle[]={@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",@"星期日"};
- for(i =0; i<7;i++)
- {
- UIButton *buttonview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- //为button显示赋值
- [buttonview setTitle:weektitle[i] forState:UIControlStateNormal];
- [buttonview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- //设置button的大小
- buttonview.frame = CGRectMake(30+i*dayWidth, 0, dayWidth, 30);
- [tableScrowView addSubview:buttonview];
- }
- #pragma mark 添加左边节数 标示
- UIView *sectionView=[[UIView alloc]initWithFrame:CGRectMake(0, 30, 30, sectionHeight*8)];
- [self.view addSubview:sectionView];
- for(i =0; i<8;i++)
- {
- //新建一个button对象 button还有一些别的属性比如背景色
- NSString *title=[NSString stringWithFormat:@"%d",i+1];
- UIButton *buttonview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
- //为button显示赋值
- buttonview.backgroundColor=[UIColor lightGrayColor];
- if (i%2) {
- [buttonview setAlpha:0.5f];
- }else{
- [buttonview setAlpha:0.7f];
- }
- [buttonview setTitle:title forState:UIControlStateNormal];
- [buttonview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- //设置button的大小
- buttonview.frame = CGRectMake(0, i*sectionHeight, 30, sectionHeight);
- [sectionView addSubview:buttonview];
-
- }
- #pragma mark 加号分割点添加
- int j;
- for (i=0; i<8; i++) {
- for (j=0; j<7; j++) {
- UILabel *lable=[[UILabel alloc]init];
- [lable setText:@"+"];
- [lable setTextColor:[UIColor lightGrayColor]];
- lable.frame=CGRectMake(30+dayWidth*i, 30+sectionHeight*j, 10, 10);
- lable.center=CGPointMake(30+dayWidth*i, sectionHeight*(j+1.5));
- [tableScrowView addSubview:lable];
- }
- }
- //添加Lesson
- [self addLesson];
- }
- #pragma mark 画课表按钮 每节课按照数组画出来
- -(void)addLesson{
-
-
- // 以下为测试数据
- UIButton *lessonBUtton=[[UIButton alloc]initWithFrame:CGRectMake(30, 30, dayWidth, sectionHeight*2)];
- [lessonBUtton setTitle:@"ios程序设计" forState:UIControlStateNormal];
- lessonBUtton.titleLabel.numberOfLines=0;
- [lessonBUtton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [lessonBUtton setBackgroundColor:[UIColor redColor]];
- [lessonBUtton.layer setCornerRadius:8.0];
- [lessonBUtton setAlpha:0.7f];
- [lessonBUtton addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
- [tableScrowView addSubview:lessonBUtton];
-
-
- UIButton *lessonBUtton1=[[UIButton alloc]initWithFrame:CGRectMake(30, 30+sectionHeight*4, dayWidth, sectionHeight*2)];
- [lessonBUtton1 setTitle:@"专业英语" forState:UIControlStateNormal];
- lessonBUtton1.titleLabel.numberOfLines=0;
- [lessonBUtton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [lessonBUtton1 setBackgroundColor:[UIColor purpleColor]];
- [lessonBUtton1.layer setCornerRadius:8.0];
- [lessonBUtton1 setAlpha:0.7f];
- [lessonBUtton1 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
- [tableScrowView addSubview:lessonBUtton1];
-
-
- UIButton *lessonBUtton12=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*2, 30+sectionHeight*3, dayWidth, sectionHeight*2)];
- [lessonBUtton12 setTitle:@"概率论" forState:UIControlStateNormal];
- lessonBUtton12.titleLabel.numberOfLines=0;
- [lessonBUtton12 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [lessonBUtton12 setBackgroundColor:[UIColor blueColor]];
- [lessonBUtton12.layer setCornerRadius:8.0];
- [lessonBUtton12 setAlpha:0.7f];
- [lessonBUtton12 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
- [tableScrowView addSubview:lessonBUtton12];
-
-
- UIButton *lessonBUtton135=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*4, 30+sectionHeight*0, dayWidth, sectionHeight*3)];
- [lessonBUtton135 setTitle:@"疯玩,疯睡。哈哈哈" forState:UIControlStateNormal];
- lessonBUtton135.titleLabel.numberOfLines=0;
- [lessonBUtton135 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [lessonBUtton135 setBackgroundColor:[UIColor brownColor]];
- [lessonBUtton135.layer setCornerRadius:8.0];
- [lessonBUtton135 setAlpha:0.7f];
- [lessonBUtton135 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
- [tableScrowView addSubview:lessonBUtton135];
-
-
-
- UIButton *lessonBUtton15=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*5, 30+sectionHeight*1, dayWidth, sectionHeight*2)];
- [lessonBUtton15 setTitle:@"专业英语" forState:UIControlStateNormal];
- lessonBUtton15.titleLabel.numberOfLines=0;
- [lessonBUtton15 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [lessonBUtton15 setBackgroundColor:[UIColor purpleColor]];
- [lessonBUtton15.layer setCornerRadius:8.0];
- [lessonBUtton15 setAlpha:0.7f];
- [lessonBUtton15 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
- [tableScrowView addSubview:lessonBUtton15];
-
- UIButton *lessonBUtton123=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*6, 30+sectionHeight*5, dayWidth, sectionHeight*2)];
- [lessonBUtton123 setTitle:@"睡觉,不写了" forState:UIControlStateNormal];
- lessonBUtton123.titleLabel.numberOfLines=0;
- [lessonBUtton123 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [lessonBUtton123 setBackgroundColor:[UIColor orangeColor]];
- [lessonBUtton123.layer setCornerRadius:8.0];
- [lessonBUtton123 setAlpha:0.7f];
- [lessonBUtton123 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
- [tableScrowView addSubview:lessonBUtton123];
-
-
- //
-
- // 此处循环创建的Button 可由tag 取出
- // for (int i=0 ; i<6; i++) {
- // UIButton *button=[UIButton alloc];
- // button.tag=4;
- // [tableScrowView addSubview:button];
- //
- //
- // }
- //
-
- }
- -(void)cellClick:(UIButton*) _button{
-
- TableCellController *tableCell=[[TableCellController alloc]init];
-
- tableCell.button=_button;
- UINavigationController *navTableCell=[[UINavigationController alloc]initWithRootViewController:tableCell];
- self.view.window.rootViewController = navTableCell;
- [UIView animateWithDuration:1 animations:^{
- }];
- }
- //
- //TableCellController *tableCell=[[TableCellController alloc]init];
- //
- //tableCell.button=_button;
- //UINavigationController *navTableCell=[[UINavigationController alloc]initWithRootViewController:tableCell];
- //[UIView transitionFromView:self.view.window.rootViewController.view
- // toView:navTableCell.view
- // duration:0.5
- // options:UIViewAnimationOptionTransitionCurlUp
- // completion:^(BOOL finished)
- // {
- // self.view.window.rootViewController = navTableCell;
- // }];
- @end
复制代码
|
|