ViewController.m中
#import "ViewController.h"
#import "CarTicketNavViewController.h"
#import "CarTivketViewController.h"
#import "ServerViewController.h"
#import "ServiceNavViewController.h"
#import "IndentViewController.h"
#import "IndentNavViewController.h"
#import "MineViewController.h"
#import "MineNavViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 创建车票预定界面
CarTivketViewController *carVC = [[CarTivketViewController alloc]init];
CarTicketNavViewController *carNav = [[CarTicketNavViewController alloc]initWithRootViewController:carVC];
carNav.tabBarItem.title = @"车票预定";
// 创建商旅服务界面
ServerViewController *serverVC = [[ServerViewController alloc]init];
ServiceNavViewController *serverNav = [[ServiceNavViewController alloc]initWithRootViewController:serverVC];
serverNav.tabBarItem.title = @"商旅服务";
// 创建订单查询界面
IndentViewController *indentVC = [[IndentViewController alloc]init];
IndentNavViewController *indentNav = [[IndentNavViewController alloc]initWithRootViewController:indentVC];
indentNav.tabBarItem.title = @"订单查询";
// 创建我的12306界面
MineViewController *mineVC = [[MineViewController alloc]init];
MineNavViewController *mineNav = [[MineNavViewController alloc]initWithRootViewController:mineVC];
mineNav.tabBarItem.title = @"我的12306";
self.viewControllers = @[carNav,serverNav,indentNav,mineNav];
}
CarTivketViewController.m中
#import "CarTivketViewController.h"#import "NextViewController.h"@interface CarTivketViewController (){
UILabel *_label1;
UILabel *_label2;
UIButton *_btn;
}
@property(nonatomic,strong)UITableView *table;
@end
@implementation CarTivketViewController
-(void)initButton:(UIButton*)btn{
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
btn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height + 25 ,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
[btn setImageEdgeInsets:UIEdgeInsetsMake(-20, 0.0,0.0, -btn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
// UITextField *text = [[UITextField alloc]init];
// text.borderStyle = UITextBorderStyleNone;
// text.frame = CGRectMake(100, 100, 100, 100);
// text.text = @"上海北京";
// [self.view addSubview:text];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"车票预定";
// 设置标题颜色及大小
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
// 设置导航栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0];
// 设置背景颜色
self.view.backgroundColor = [UIColor whiteColor];
// 设置表格的位置及大小
self.table = [[UITableView alloc]initWithFrame:self.view.frame];
self.table.delegate = self;
self.table.dataSource = self;
[self.view addSubview:self.table];
// 温馨提示
UILabel *reminderLab = [[UILabel alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 44 - 60, [UIScreen mainScreen].bounds.size.width, 60)];
reminderLab.numberOfLines = 0;
reminderLab.backgroundColor = [UIColor colorWithRed:(244 / 255.0) green:(243 / 255.0) blue:(150 / 255.0) alpha:0.7];
reminderLab.font = [UIFont systemFontOfSize:13];
reminderLab.text = @"温馨提示:铁路12306每日06:00~23:00提供服务,在铁路12306购票、改签和退票须不晚于开车前30分钟";
[self.view addSubview:reminderLab];
}
#pragma mark UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 6;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@""];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switch (indexPath.row) {
case 0:
{
for (int i = 0; i < 4; i++) {
NSArray *arr = @[@"正晚点",@"温馨服务",@"订餐服务",@"约车"];
CGFloat leftleight = 2;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button = [[UIButton alloc] initWithFrame:CGRectMake(i * [UIScreen mainScreen].bounds.size.width / 4 + leftleight, 10, [UIScreen mainScreen].bounds.size.width / 4 - leftleight * 2, 80)];
[button setImage:[UIImage imageNamed:@"xiaoXi.png"] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont systemFontOfSize:16]];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeColor:) forControlEvents:UIControlEventTouchUpInside];
[button setTitle:arr[i] forState:UIControlStateNormal];
[self initButton:button];
[cell addSubview:button];
}
}
break;
case 1:
{
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 7, 20, [UIScreen mainScreen].bounds.size.width / 7, 60)];
label1.text = @"北京";
label1.font = [UIFont systemFontOfSize:23 weight:2];
[cell addSubview:label1];
_label1 = label1;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake([UIScreen mainScreen].bounds.size.width / 7 * 3, 20, [UIScreen mainScreen].bounds.size.width / 7, 60);
[button setImage:[UIImage imageNamed:@"224"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(changeText:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width / 7 * 5, 20, [UIScreen mainScreen].bounds.size.width / 7, 60)];
label2.text = @"上海";
label2.font = [UIFont systemFontOfSize:23 weight:2];
[cell addSubview:label2];
_label2 = label2;
}
break;
case 2:
{
// 上边距
CGFloat top = 23;
for (int i = 0; i < 3; i++) {
UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(20, i * 75 + top, 100, 30)];
NSArray *arr = @[@"出发日期",@"出发时间",@"席 别"];
label1.text = arr[i];
label1.textColor = [UIColor grayColor];
[cell addSubview:label1];
UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(120, i * 75 + top, 140, 30)];
NSArray *arr2 = @[@"2017-10-17",@"00:00--24:00",@"不限"];
label2.text = arr2[i];
[cell addSubview:label2];
// UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(280, top, 100, 30)];
// label3.text = @"学生";
// [cell addSubview:label3];
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(280, top, 100, 30)];
[button setTitle:@"学生" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"cart_unSelect_btn"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"cart_selected_btn"] forState:UIControlStateSelected];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickSelect:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
}
}
break;
case 3:
{
for (int i = 0; i < 6; i++) {
CGFloat left = 10;
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(i * 65 + left, 7, 65, 46)];
NSArray *arr = @[@"全部",@"G/D/C",@"Z字头",@"T字头",@"K字头",@"其他"];
[button setTitle:arr[i] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.layer.cornerRadius = 5;
button.tag = 100 + i;
[button addTarget:self action:@selector(clickColor:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:button];
}
}
break;
case 4:
{
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 5, 100, 40)];
[button setTitle:@"乘客" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"icon_add"] forState:UIControlStateNormal];
[button setTitleColor:[UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickAdd:) forControlEvents:UIControlEventTouchUpInside];
// button.titleLabel.font = [UIFont systemFontOfSize:19];
// [button setTitleEdgeInsets:UIEdgeInsetsMake(0, - button.imageView.frame.size.width, 0, button.imageView.frame.size.width)];
// [button setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
[cell addSubview:button];
UIButton *referBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 80, [UIScreen mainScreen].bounds.size.width - 15*2, 40)];
referBtn.backgroundColor = [UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0];
[referBtn setTitle:@"查询" forState:UIControlStateNormal];
[referBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
referBtn.layer.cornerRadius = 7;
[referBtn addTarget:self action:@selector(clickcRefer:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:referBtn];
UIView *line = [[UIView alloc]initWithFrame:CGRectMake(15, 150, referBtn.frame.size.width / 2 - 50, 1)];
line.backgroundColor = [UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0];
[cell addSubview:line];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(referBtn.frame.size.width / 2 - 37, 135, 100, 30)];
label.text = @"最近常用线路";
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor grayColor];
label.font = [UIFont systemFontOfSize:13];
[cell addSubview:label];
UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(referBtn.frame.size.width / 2 + 60, 150, referBtn.frame.size.width / 2 - 50, 1)];
line2.backgroundColor = [UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0];
[cell addSubview:line2];
}
break;
case 5:
{
}
break;
default:
break;
}
return cell;
}
-(void)clickSelect:(UIButton *)sender{
NSLog(@"选中/未选中");
sender.selected = !sender.selected;
}
-(void)clickcRefer:(UIButton *)sender{
NSLog(@"点击查询");
NextViewController *next = [[NextViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
}
-(void)clickAdd:(UIButton *)sender{
NSLog(@"点击添加乘客");
}
-(void)clickColor:(UIButton *)sender{
NSLog(@"点击选中");
NSLog(@"%ld",(long)sender.tag);
for (int i = 0; i < 6; i++) {
UIButton *btn = (UIButton *)[[sender superview]viewWithTag:100 + i];
[btn setBackgroundColor:[UIColor clearColor]];
}
UIButton *button = (UIButton *)sender;
[button setBackgroundColor:[UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0]];
}
-(void)changeText:(UIButton *)button{
NSLog(@"点击转换位置");
NSString *str1 = _label1.text;
_label1.text = _label2.text;
_label2.text = str1;
}
-(void)changeColor:(UIButton *)button{
NSLog(@"点击按钮!");
}
// 行高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
return 90;
break;
case 1:
return 90;
break;
case 2:
return 210;
break;
case 3:
return 60;
break;
case 4:
return 180;
break;
case 5:
return 200;
break;
default:
break;
}
return 0;
}
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.tabBarController.tabBar.hidden = NO;
}
NextViewController.m中
#import "NextViewController.h"
@interface NextViewController ()
@end
@implementation NextViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"北京<>上海";
UIButton *rightitem = [[UIButton alloc]init];
[rightitem setImage:[UIImage imageNamed:@"dongTai"] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightitem];
}
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.tabBarController.tabBar.hidden = YES;
}
网友评论