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];
// 創(chuàng)建車票預(yù)定界面
CarTivketViewController *carVC = [[CarTivketViewController alloc]init];
CarTicketNavViewController *carNav = [[CarTicketNavViewController alloc]initWithRootViewController:carVC];
carNav.tabBarItem.title = @"車票預(yù)定";
// 創(chuàng)建商旅服務(wù)界面
ServerViewController *serverVC = [[ServerViewController alloc]init];
ServiceNavViewController *serverNav = [[ServiceNavViewController alloc]initWithRootViewController:serverVC];
serverNav.tabBarItem.title = @"商旅服務(wù)";
// 創(chuàng)建訂單查詢界面
IndentViewController *indentVC = [[IndentViewController alloc]init];
IndentNavViewController *indentNav = [[IndentNavViewController alloc]initWithRootViewController:indentVC];
indentNav.tabBarItem.title = @"訂單查詢";
// 創(chuàng)建我的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 = @"車票預(yù)定";
// 設(shè)置標(biāo)題顏色及大小
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
// 設(shè)置導(dǎo)航欄顏色
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:(48 / 255.0) green:(140 / 255.0) blue:(204 / 255.0) alpha:1.0];
// 設(shè)置背景顏色
self.view.backgroundColor = [UIColor whiteColor];
// 設(shè)置表格的位置及大小
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提供服務(wù)当船,在鐵路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 = @[@"正晚點(diǎn)",@"溫馨服務(wù)",@"訂餐服務(wù)",@"約車"];
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 = @[@"出發(fā)日期",@"出發(fā)時間",@"席 別"];
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 = @"學(xué)生";
// [cell addSubview:label3];
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(280, top, 100, 30)];
[button setTitle:@"學(xué)生" 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(@"點(diǎn)擊查詢");
NextViewController *next = [[NextViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
}
-(void)clickAdd:(UIButton *)sender{
NSLog(@"點(diǎn)擊添加乘客");
}
-(void)clickColor:(UIButton *)sender{
NSLog(@"點(diǎn)擊選中");
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(@"點(diǎn)擊轉(zhuǎn)換位置");
NSString *str1 = _label1.text;
_label1.text = _label2.text;
_label2.text = str1;
}
-(void)changeColor:(UIButton *)button{
NSLog(@"點(diǎn)擊按鈕!");
}
// 行高
-(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;
}