仿12306首页

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;

}
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,277评论 6 503
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,689评论 3 393
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,624评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,356评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,402评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,292评论 1 301
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,135评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,992评论 0 275
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,429评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,636评论 3 334
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,785评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,492评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,092评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,723评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,858评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,891评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,713评论 2 354

推荐阅读更多精彩内容