iOS 课程表 源码 实例

思路按照起始点位置和宽高比例进行button 的添加  1 //
  2 //  TableController.m
  3 //  hedaAssistant
  4 //
  5 //  Created by bear on 15/11/28.
  6 //  Copyright © 2015年 bear. All rights reserved.
  7 //
  8
  9 #import "TableController.h"
 10 #import "TableCellController.h"
 11 #import "UINavigationItem+custom.h"
 12
 13
 14 //获取屏幕 宽度、高度
 15 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
 16 #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
 17
 18
 19 //NavBar高度
 20 #define NavigationBar_HEIGHT 44
 21 #define StatusBar_HEIGHT 20
 22 #define TabBar_HEIGHT 49
 23
 24 @interface TableController (){
 25     UIScrollView *tableScrowView;
 26     CGFloat  dayWidth;
 27     CGFloat  sectionHeight;
 28
 29 }@end
 30
 31 @implementation TableController
 32 -(void)viewDidLoad{
 33
 34
 35     [self setUI];
 36
 37 }
 38
 39
 40
 41 -(void)setUI{
 42
 43
 44     //设置  导航栏的背景
 45     [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"tabbar_background.png"] forBarMetrics:UIBarMetricsDefault];
 46
 47     //设置自己的标题x
 48     [self.navigationItem setMyTitle:@"考试安排表"];
 49
 50
 51
 52
 53
 54
 55     //添加整体背景
 56
 57     UIImage *bgImg=[UIImage imageNamed:@"main.png"];
 58     UIImageView *mainBgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-(StatusBar_HEIGHT+NavigationBar_HEIGHT+TabBar_HEIGHT))];
 59     mainBgView.image=bgImg;
 60     [self.view addSubview:mainBgView];
 61
 62     //添加顶部星期背景
 63     UIView *headBg=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 30)];
 64     [headBg setAlpha:0.7f];
 65     headBg.backgroundColor=[UIColor orangeColor];
 66     [self.view addSubview:headBg];
 67
 68
 69     //定义基本宽高
 70       dayWidth=(CGFloat) (SCREEN_WIDTH-30)/5;
 71       sectionHeight=(CGFloat)(SCREEN_HEIGHT-(StatusBar_HEIGHT+NavigationBar_HEIGHT+TabBar_HEIGHT)-30)/8;
 72
 73
 74 #pragma mark    添加ScrowView能左右滚动
 75     tableScrowView=[[UIScrollView alloc]init];
 76     tableScrowView.frame=CGRectMake(0, 0, SCREEN_WIDTH,sectionHeight*8+35);
 77     tableScrowView.contentSize =  CGSizeMake(dayWidth*7+30, 0);
 78     tableScrowView.bounces=NO;
 79     [self.view addSubview:tableScrowView];
 80
 81
 82 #pragma mark  添加星期头部
 83
 84     int i;
 85     NSString *weektitle[]={@"星期一",@"星期二",@"星期三",@"星期四",@"星期五",@"星期六",@"星期日"};
 86     for(i =0; i<7;i++)
 87     {
 88         UIButton *buttonview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 89         //为button显示赋值
 90
 91         [buttonview setTitle:weektitle[i] forState:UIControlStateNormal];
 92         [buttonview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
 93         //设置button的大小
 94         buttonview.frame = CGRectMake(30+i*dayWidth, 0, dayWidth, 30);
 95         [tableScrowView addSubview:buttonview];
 96
 97
 98
 99
100     }
101
102
103 #pragma mark   添加左边节数 标示
104     UIView *sectionView=[[UIView alloc]initWithFrame:CGRectMake(0, 30, 30, sectionHeight*8)];
105     [self.view addSubview:sectionView];
106     for(i =0; i<8;i++)
107     {
108         //新建一个button对象 button还有一些别的属性比如背景色
109         NSString *title=[NSString stringWithFormat:@"%d",i+1];
110         UIButton *buttonview = [UIButton buttonWithType:UIButtonTypeRoundedRect];
111         //为button显示赋值
112         buttonview.backgroundColor=[UIColor lightGrayColor];
113         if (i%2) {
114             [buttonview setAlpha:0.5f];
115         }else{
116             [buttonview setAlpha:0.7f];
117         }
118
119         [buttonview setTitle:title forState:UIControlStateNormal];
120         [buttonview setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
121         //设置button的大小
122         buttonview.frame = CGRectMake(0, i*sectionHeight, 30, sectionHeight);
123         [sectionView addSubview:buttonview];
124
125
126     }
127
128
129
130 #pragma mark 加号分割点添加
131     int j;
132     for (i=0; i<8; i++) {
133         for (j=0; j<7; j++) {
134             UILabel *lable=[[UILabel alloc]init];
135             [lable setText:@"+"];
136             [lable setTextColor:[UIColor lightGrayColor]];
137                         lable.frame=CGRectMake(30+dayWidth*i, 30+sectionHeight*j, 10, 10);
138                   lable.center=CGPointMake(30+dayWidth*i, sectionHeight*(j+1.5));
139             [tableScrowView addSubview:lable];
140         }
141     }
142
143
144
145
146
147
148
149
150 //添加Lesson
151     [self addLesson];
152
153 }
154
155
156
157
158 #pragma mark   画课表按钮 每节课按照数组画出来
159 -(void)addLesson{
160
161
162     // 以下为测试数据
163     UIButton *lessonBUtton=[[UIButton alloc]initWithFrame:CGRectMake(30, 30, dayWidth, sectionHeight*2)];
164     [lessonBUtton setTitle:@"ios程序设计" forState:UIControlStateNormal];
165     lessonBUtton.titleLabel.numberOfLines=0;
166     [lessonBUtton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
167     [lessonBUtton setBackgroundColor:[UIColor redColor]];
168     [lessonBUtton.layer setCornerRadius:8.0];
169     [lessonBUtton setAlpha:0.7f];
170     [lessonBUtton addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
171     [tableScrowView addSubview:lessonBUtton];
172
173
174
175     UIButton *lessonBUtton1=[[UIButton alloc]initWithFrame:CGRectMake(30, 30+sectionHeight*4, dayWidth, sectionHeight*2)];
176     [lessonBUtton1 setTitle:@"专业英语" forState:UIControlStateNormal];
177     lessonBUtton1.titleLabel.numberOfLines=0;
178     [lessonBUtton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
179     [lessonBUtton1 setBackgroundColor:[UIColor purpleColor]];
180     [lessonBUtton1.layer setCornerRadius:8.0];
181     [lessonBUtton1 setAlpha:0.7f];
182     [lessonBUtton1 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
183     [tableScrowView addSubview:lessonBUtton1];
184
185
186     UIButton *lessonBUtton12=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*2, 30+sectionHeight*3, dayWidth, sectionHeight*2)];
187     [lessonBUtton12 setTitle:@"概率论" forState:UIControlStateNormal];
188     lessonBUtton12.titleLabel.numberOfLines=0;
189     [lessonBUtton12 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
190     [lessonBUtton12 setBackgroundColor:[UIColor blueColor]];
191     [lessonBUtton12.layer setCornerRadius:8.0];
192     [lessonBUtton12 setAlpha:0.7f];
193     [lessonBUtton12 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
194     [tableScrowView addSubview:lessonBUtton12];
195
196
197     UIButton *lessonBUtton135=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*4, 30+sectionHeight*0, dayWidth, sectionHeight*3)];
198     [lessonBUtton135 setTitle:@"疯玩,疯睡。哈哈哈" forState:UIControlStateNormal];
199     lessonBUtton135.titleLabel.numberOfLines=0;
200     [lessonBUtton135 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
201     [lessonBUtton135 setBackgroundColor:[UIColor brownColor]];
202     [lessonBUtton135.layer setCornerRadius:8.0];
203     [lessonBUtton135 setAlpha:0.7f];
204     [lessonBUtton135 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
205     [tableScrowView addSubview:lessonBUtton135];
206
207
208
209     UIButton *lessonBUtton15=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*5, 30+sectionHeight*1, dayWidth, sectionHeight*2)];
210     [lessonBUtton15 setTitle:@"专业英语" forState:UIControlStateNormal];
211     lessonBUtton15.titleLabel.numberOfLines=0;
212     [lessonBUtton15 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
213     [lessonBUtton15 setBackgroundColor:[UIColor purpleColor]];
214     [lessonBUtton15.layer setCornerRadius:8.0];
215     [lessonBUtton15 setAlpha:0.7f];
216     [lessonBUtton15 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
217     [tableScrowView addSubview:lessonBUtton15];
218
219     UIButton *lessonBUtton123=[[UIButton alloc]initWithFrame:CGRectMake(30+dayWidth*6, 30+sectionHeight*5, dayWidth, sectionHeight*2)];
220     [lessonBUtton123 setTitle:@"睡觉,不写了" forState:UIControlStateNormal];
221     lessonBUtton123.titleLabel.numberOfLines=0;
222     [lessonBUtton123 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
223     [lessonBUtton123 setBackgroundColor:[UIColor orangeColor]];
224     [lessonBUtton123.layer setCornerRadius:8.0];
225     [lessonBUtton123 setAlpha:0.7f];
226     [lessonBUtton123 addTarget:self action:@selector(cellClick:) forControlEvents:UIControlEventTouchUpInside];
227     [tableScrowView addSubview:lessonBUtton123];
228
229
230 //
231
232 //     此处循环创建的Button  可由tag   取出
233 //    for (int i=0 ; i<6; i++) {
234 //        UIButton *button=[UIButton alloc];
235 //        button.tag=4;
236 //        [tableScrowView addSubview:button];
237 //
238 //
239 //    }
240 //
241
242
243 }
244
245
246
247
248 -(void)cellClick:(UIButton*) _button{
249
250     TableCellController *tableCell=[[TableCellController alloc]init];
251
252     tableCell.button=_button;
253     UINavigationController *navTableCell=[[UINavigationController alloc]initWithRootViewController:tableCell];
254
255          self.view.window.rootViewController = navTableCell;
256
257
258
259 }
260
261
262 //
263 //TableCellController *tableCell=[[TableCellController alloc]init];
264 //
265 //tableCell.button=_button;
266 //UINavigationController *navTableCell=[[UINavigationController alloc]initWithRootViewController:tableCell];
267 //[UIView transitionFromView:self.view.window.rootViewController.view
268 //                    toView:navTableCell.view
269 //                  duration:0.5
270 //                   options:UIViewAnimationOptionTransitionCurlUp
271 //                completion:^(BOOL finished)
272 // {
273 //     self.view.window.rootViewController = navTableCell;
274 // }];
275
276
277
278 @end

源码下载地址     https://github.com/xiaocaiabc/hedaAssistant.git

时间: 2024-10-14 16:23:07

iOS 课程表 源码 实例的相关文章

财付通支付接口完整源码实例php版

财付通支付接口完整源码实例php版 版权声明:本文为博主原创文章,未经博主允许不得转载. 支付动作文件: [php] view plain copy <?php //------------------ 参数开始 ------------------ //商户号 $bargainor_id='45698236888'; //密钥 $key='sjdlfjsdifjieojf454654'; //返回地址 $return_url="http://".$_SERVER['HTTP_H

IOS游戏源码下载之简易版雷电(2.2.3版本)源码完整下载和简单开发教程

 头回写教程这玩意,真不知道要写些什么,所以主要就是共享下我的代码,和一些重要功能的讲解吧,各位如果有啥不懂的可以回帖提问哟. 其实这个demo(为何叫demo呢,因为我真不敢称这个为游戏呀)是我初学cocos2d-x两周的时候写的,所以可能写的不是很好(好吧,其实现在写的东西也不好),当初主要还是靠着度娘和TestCpp学的,所以在此还是要强调一下TestCpp的重要性,要好好把它看一遍哟,以后你想实现什么功能就可以去翻看了. 好了,言归正传,还是介绍下我写的这个demo了,在此先华丽丽的

大写金额换算器iOS版源码

大写金额换算器iOS版源码 人民币金额大写转换器输入数字就可以转换成相应的人民币大写金额,操作很easy,需一键点击,就可以复制. 是財务办公人员必备的小工具. 银行.单位和个人填写的各种票据和结算凭证是办理支付结算和现金收付的重要根据,直接关系到支付结算的准确.及时和安全.票据和结算凭证是银行.单位和个人凭以记载账务的会计凭证.是记载经济业务和明白经济责任的一种书面证明.因此,填写票据和结算凭证必须做到标准化.规范化.要素齐全.数字正确.字迹清晰.不错漏.不潦草.防止涂改. 中文大写金额数字应

C#获取网页HTML源码实例

本文实例讲述了C#获取网页HTML源码的方法,分享给大家供大家参考.具体方法如下: 关键代码如下: 代码如下: /// <summary> /// 获取网页HTML源码 /// </summary> /// <param name="url">链接 eg:http://www.baidu.com/ </param> /// <param name="charset">编码 eg:Encoding.UTF8&

3000套IOS android源码分享 7.2G UI素材

这些资源都是自学的时候收集的,现在整理打包好,分享给各位小伙伴. UI素材(7.2G)  http://tianmaying.com/topic/8ab3eda84e1a1408014e1b2117ed0066 android源码:    http://tianmaying.com/topic/8ab3eda84e1a1408014e1bbe3a3c0073 IOS源码:         http://tianmaying.com/topic/8ab3eda84e1fc18e014e253c48

高仿BiliBili的iOS客户端源码项目

高高高仿BiliBili的iOS客户端 我感觉吧~安卓的客户端真的比iOS的漂亮许多啊~!!!! 自己防的BiliBili,功能还在完善中··· 最近忙着找工作就没更新了 借鉴了许多作者的思路,b站得API拿的差不多,新人写的代码,慎重考虑后在下载,对格式有洁癖的会疯 >-< 源码下载:http://code.662p.com/view/13680.html <ignore_js_op> <ignore_js_op> 详细说明:http://ios.662p.com/t

iOS AFNetWorking源码详解(一)

来源:Yuzeyang 链接:http://zeeyang.com/2016/02/21/AFNetWorking-one/ 首先来介绍下AFNetWorking,官方介绍如下: AFNetworking is a delightful networking library for iOS and Mac OS X. It’s built on top of theFoundation URL Loading System, extending the powerful high-level n

能够附加图片的标签控件iOS项目源码

这个源码案例是能够附加图片的标签控件,源码JTImageLabel,JTImageLabel能够附加图片的标签Label控件,图片可以随意更换.位置也能够很好的控制.效果图: <ignore_js_op> 使用方法: 支持CocoaPods: pod 'JTImageLabel', '~> 1.0' 用法相当简单,像普通Label那样使用: #import "JTImageLabel.h" @property (weak, nonatomic) IBOutlet JT

高仿一元云购IOS应用源码项目

高仿一元云购IOS应用(高仿自一元云购安卓客户端) 本App因官方没有IOS客户端故开发,利用业务时间历时2个星期,终于开发完成,又因苹果的各大审核规则对此App的影响,又历时1个多月才终于成功上架,上架两天,用户量成功破千.But,因官方觉得咱涉及侵权,故鄙人从AppStore下架,故今日将此Ap分享给大家学习一下吧. 因版权问题,本次开源将不提供一元云购的官方接口地址,地址都将以www.xxx.com替换,如果看官需要正常运行,请自行抓包获得,见谅. 1.本App使用MVC框架完成开发.2.