A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 15223245 中级黑马   /  2016-1-13 09:07  /  3438 人查看  /  25 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. <div class="blockcode"><blockquote>//
  2. //  TableController.m
  3. //  hedaAssistant
  4. //
  5. //  Created by bear on 15/11/28.
  6. //  Copyright © 2015年 bear. All rights reserved.
  7. //

  8. #import "TableController.h"
  9. #import "TableCellController.h"
  10. #import "UINavigationItem+custom.h"


  11. //获取屏幕 宽度、高度
  12. #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
  13. #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)


  14. //NavBar高度
  15. #define NavigationBar_HEIGHT 44
  16. #define StatusBar_HEIGHT 20
  17. #define TabBar_HEIGHT 49

  18. @interface TableController (){
  19.     UIScrollView *tableScrowView;
  20.     CGFloat  dayWidth;
  21.     CGFloat  sectionHeight;

  22. }@end

  23. @implementation TableController
  24. -(void)viewDidLoad{


  25.     [self setUI];

  26. }



  27. -(void)setUI{


  28.     //设置  导航栏的背景
  29.     [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tabbar_background.png"] forBarMetrics:UIBarMetricsDefault];

  30.     //设置自己的标题x
  31.     [self.navigationItem setMyTitle:@"考试安排表"];






  32.     //添加整体背景

  33.     UIImage *bgImg=[UIImage imageNamed:@"main.png"];
  34.     UIImageView *mainBgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(StatusBar_HEIGHT+NavigationBar_HEIGHT+TabBar_HEIGHT))];
  35.     mainBgView.image=bgImg;
  36.     [self.view addSubview:mainBgView];

  37.     //添加顶部星期背景
  38.     UIView *headBg=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
  39.     [headBg setAlpha:0.7f];
  40.     headBg.backgroundColor=[UIColor orangeColor];
  41.     [self.view addSubview:headBg];


  42.     //定义基本宽高
  43.       dayWidth=(CGFloat) (SCREEN_WIDTH-30)/5;
  44.       sectionHeight=(CGFloat)(SCREEN_HEIGHT-(StatusBar_HEIGHT+NavigationBar_HEIGHT+TabBar_HEIGHT)-30)/8;
  45.    
  46.    
  47. #pragma mark    添加ScrowView能左右滚动
  48.     tableScrowView=[[UIScrollView alloc]init];
  49.     tableScrowView.frame=CGRectMake(0, 0, SCREEN_WIDTH,sectionHeight*8+35);
  50.     tableScrowView.contentSize =  CGSizeMake(dayWidth*7+30, 0);
  51.     tableScrowView.bounces=NO;
  52.     [self.view addSubview:tableScrowView];
  53.    

  54. #pragma mark  添加星期头部

  55.     int i;
  56.     NSString *weektitle[]={@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",@"星期日"};
  57.     for(i =0; i<7;i++)
  58.     {
  59.         UIButton *buttonview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  60.         //为button显示赋值

  61.         [buttonview setTitle:weektitle[i] forState:UIControlStateNormal];
  62.         [buttonview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  63.         //设置button的大小
  64.         buttonview.frame = CGRectMake(30+i*dayWidth, 0, dayWidth, 30);
  65.         [tableScrowView addSubview:buttonview];




  66.     }


  67. #pragma mark   添加左边节数 标示
  68.     UIView *sectionView=[[UIView alloc]initWithFrame:CGRectMake(0, 30, 30, sectionHeight*8)];
  69.     [self.view addSubview:sectionView];
  70.     for(i =0; i<8;i++)
  71.     {
  72.         //新建一个button对象 button还有一些别的属性比如背景色
  73.         NSString *title=[NSString stringWithFormat:@"%d",i+1];
  74.         UIButton *buttonview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  75.         //为button显示赋值
  76.         buttonview.backgroundColor=[UIColor lightGrayColor];
  77.         if (i%2) {
  78.             [buttonview setAlpha:0.5f];
  79.         }else{
  80.             [buttonview setAlpha:0.7f];
  81.         }

  82.         [buttonview setTitle:title forState:UIControlStateNormal];
  83.         [buttonview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  84.         //设置button的大小
  85.         buttonview.frame = CGRectMake(0, i*sectionHeight, 30, sectionHeight);
  86.         [sectionView addSubview:buttonview];

  87.         
  88.     }



  89. #pragma mark 加号分割点添加
  90.     int j;
  91.     for (i=0; i<8; i++) {
  92.         for (j=0; j<7; j++) {
  93.             UILabel *lable=[[UILabel alloc]init];
  94.             [lable setText:@"+"];
  95.             [lable setTextColor:[UIColor lightGrayColor]];
  96.                         lable.frame=CGRectMake(30+dayWidth*i, 30+sectionHeight*j, 10, 10);
  97.                   lable.center=CGPointMake(30+dayWidth*i, sectionHeight*(j+1.5));
  98.             [tableScrowView addSubview:lable];
  99.         }
  100.     }








  101. //添加Lesson   
  102.     [self addLesson];

  103. }




  104. #pragma mark   画课表按钮 每节课按照数组画出来
  105. -(void)addLesson{
  106.    
  107.    
  108.     // 以下为测试数据
  109.     UIButton *lessonBUtton=[[UIButton alloc]initWithFrame:CGRectMake(30, 30, dayWidth, sectionHeight*2)];
  110.     [lessonBUtton setTitle:@"ios程序设计" forState:UIControlStateNormal];
  111.     lessonBUtton.titleLabel.numberOfLines=0;
  112.     [lessonBUtton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  113.     [lessonBUtton setBackgroundColor:[UIColor redColor]];
  114.     [lessonBUtton.layer setCornerRadius:8.0];
  115.     [lessonBUtton setAlpha:0.7f];
  116.     [lessonBUtton addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
  117.     [tableScrowView addSubview:lessonBUtton];
  118.    

  119.    
  120.     UIButton *lessonBUtton1=[[UIButton alloc]initWithFrame:CGRectMake(30, 30+sectionHeight*4, dayWidth, sectionHeight*2)];
  121.     [lessonBUtton1 setTitle:@"专业英语" forState:UIControlStateNormal];
  122.     lessonBUtton1.titleLabel.numberOfLines=0;
  123.     [lessonBUtton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  124.     [lessonBUtton1 setBackgroundColor:[UIColor purpleColor]];
  125.     [lessonBUtton1.layer setCornerRadius:8.0];
  126.     [lessonBUtton1 setAlpha:0.7f];
  127.     [lessonBUtton1 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
  128.     [tableScrowView addSubview:lessonBUtton1];
  129.    
  130.    
  131.     UIButton *lessonBUtton12=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*2, 30+sectionHeight*3, dayWidth, sectionHeight*2)];
  132.     [lessonBUtton12 setTitle:@"概率论" forState:UIControlStateNormal];
  133.     lessonBUtton12.titleLabel.numberOfLines=0;
  134.     [lessonBUtton12 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  135.     [lessonBUtton12 setBackgroundColor:[UIColor blueColor]];
  136.     [lessonBUtton12.layer setCornerRadius:8.0];
  137.     [lessonBUtton12 setAlpha:0.7f];
  138.     [lessonBUtton12 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
  139.     [tableScrowView addSubview:lessonBUtton12];
  140.    
  141.    
  142.     UIButton *lessonBUtton135=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*4, 30+sectionHeight*0, dayWidth, sectionHeight*3)];
  143.     [lessonBUtton135 setTitle:@"疯玩,疯睡。哈哈哈" forState:UIControlStateNormal];
  144.     lessonBUtton135.titleLabel.numberOfLines=0;
  145.     [lessonBUtton135 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  146.     [lessonBUtton135 setBackgroundColor:[UIColor brownColor]];
  147.     [lessonBUtton135.layer setCornerRadius:8.0];
  148.     [lessonBUtton135 setAlpha:0.7f];
  149.     [lessonBUtton135 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
  150.     [tableScrowView addSubview:lessonBUtton135];
  151.    
  152.    
  153.    
  154.     UIButton *lessonBUtton15=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*5, 30+sectionHeight*1, dayWidth, sectionHeight*2)];
  155.     [lessonBUtton15 setTitle:@"专业英语" forState:UIControlStateNormal];
  156.     lessonBUtton15.titleLabel.numberOfLines=0;
  157.     [lessonBUtton15 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  158.     [lessonBUtton15 setBackgroundColor:[UIColor purpleColor]];
  159.     [lessonBUtton15.layer setCornerRadius:8.0];
  160.     [lessonBUtton15 setAlpha:0.7f];
  161.     [lessonBUtton15 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
  162.     [tableScrowView addSubview:lessonBUtton15];
  163.    
  164.     UIButton *lessonBUtton123=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*6, 30+sectionHeight*5, dayWidth, sectionHeight*2)];
  165.     [lessonBUtton123 setTitle:@"睡觉,不写了" forState:UIControlStateNormal];
  166.     lessonBUtton123.titleLabel.numberOfLines=0;
  167.     [lessonBUtton123 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  168.     [lessonBUtton123 setBackgroundColor:[UIColor orangeColor]];
  169.     [lessonBUtton123.layer setCornerRadius:8.0];
  170.     [lessonBUtton123 setAlpha:0.7f];
  171.     [lessonBUtton123 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
  172.     [tableScrowView addSubview:lessonBUtton123];
  173.    
  174.    
  175. //
  176.    
  177. //     此处循环创建的Button  可由tag   取出
  178. //    for (int i=0 ; i<6; i++) {
  179. //        UIButton *button=[UIButton alloc];
  180. //        button.tag=4;
  181. //        [tableScrowView addSubview:button];
  182. //        
  183. //        
  184. //    }
  185. //
  186.    

  187. }




  188. -(void)cellClick:(UIButton*) _button{
  189.    
  190.     TableCellController *tableCell=[[TableCellController alloc]init];
  191.    
  192.     tableCell.button=_button;
  193.     UINavigationController *navTableCell=[[UINavigationController alloc]initWithRootViewController:tableCell];
  194.        self.view.window.rootViewController = navTableCell;

  195.         [UIView animateWithDuration:1 animations:^{

  196.         }];




  197. }


  198. //
  199. //TableCellController *tableCell=[[TableCellController alloc]init];
  200. //
  201. //tableCell.button=_button;
  202. //UINavigationController *navTableCell=[[UINavigationController alloc]initWithRootViewController:tableCell];
  203. //[UIView transitionFromView:self.view.window.rootViewController.view
  204. //                    toView:navTableCell.view
  205. //                  duration:0.5
  206. //                   options:UIViewAnimationOptionTransitionCurlUp
  207. //                completion:^(BOOL finished)
  208. // {
  209. //     self.view.window.rootViewController = navTableCell;
  210. // }];



  211. @end
复制代码


25 个回复

倒序浏览
谢谢亲的分享
回复 使用道具 举报
谢谢亲的分享
回复 使用道具 举报
不清楚的可以私聊

评分

参与人数 1黑马币 +2 收起 理由
AUASBUB + 2

查看全部评分

回复 使用道具 举报
谢谢!!!1
回复 使用道具 举报
233333333333333333333333333
回复 使用道具 举报
木叶 中级黑马 2016-1-14 21:22:30
7#
要顶一下!!!
回复 使用道具 举报
谢了。。。。。。。
回复 使用道具 举报
谢谢。。。。。。。
回复 使用道具 举报
这都可以
回复 使用道具 举报
太坑了吧
回复 使用道具 举报
guyuexing 来自手机 中级黑马 2016-1-17 10:03:10
12#
谢谢分享
回复 使用道具 举报
每天水一水
回复 使用道具 举报
要不要这么长???
回复 使用道具 举报
ak13211 发表于 2016-1-19 13:59
要不要这么长???

等咱到了就业班都是这么长
回复 使用道具 举报
留名。。。。。。。。
回复 使用道具 举报
谢谢分享代码
回复 使用道具 举报
sunshine429 来自手机 中级黑马 2016-1-20 23:56:06
18#
非常棒,顶一顶!!
回复 使用道具 举报
感谢亲的分享
回复 使用道具 举报
guyuexing 来自手机 中级黑马 2016-1-21 09:49:36
20#
谢谢分享
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 加入黑马