仿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];



    // 創(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;

}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市胁艰,隨后出現(xiàn)的幾起案子底洗,更是在濱河造成了極大的恐慌腋么,老刑警劉巖,帶你破解...
    沈念sama閱讀 207,248評論 6 481
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件亥揖,死亡現(xiàn)場離奇詭異珊擂,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)费变,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 88,681評論 2 381
  • 文/潘曉璐 我一進(jìn)店門摧扇,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人挚歧,你說我怎么就攤上這事扛稽。” “怎么了昼激?”我有些...
    開封第一講書人閱讀 153,443評論 0 344
  • 文/不壞的土叔 我叫張陵庇绽,是天一觀的道長。 經(jīng)常有香客問我橙困,道長瞧掺,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 55,475評論 1 279
  • 正文 為了忘掉前任凡傅,我火速辦了婚禮辟狈,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己哼转,他們只是感情好明未,可當(dāng)我...
    茶點(diǎn)故事閱讀 64,458評論 5 374
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著壹蔓,像睡著了一般趟妥。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上佣蓉,一...
    開封第一講書人閱讀 49,185評論 1 284
  • 那天披摄,我揣著相機(jī)與錄音,去河邊找鬼勇凭。 笑死疚膊,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的虾标。 我是一名探鬼主播寓盗,決...
    沈念sama閱讀 38,451評論 3 401
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼璧函!你這毒婦竟也來了傀蚌?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,112評論 0 261
  • 序言:老撾萬榮一對情侶失蹤蘸吓,失蹤者是張志新(化名)和其女友劉穎喳张,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體美澳,經(jīng)...
    沈念sama閱讀 43,609評論 1 300
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,083評論 2 325
  • 正文 我和宋清朗相戀三年摸航,在試婚紗的時候發(fā)現(xiàn)自己被綠了制跟。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,163評論 1 334
  • 序言:一個原本活蹦亂跳的男人離奇死亡酱虎,死狀恐怖雨膨,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情读串,我是刑警寧澤聊记,帶...
    沈念sama閱讀 33,803評論 4 323
  • 正文 年R本政府宣布,位于F島的核電站恢暖,受9級特大地震影響排监,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜杰捂,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,357評論 3 307
  • 文/蒙蒙 一舆床、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦挨队、人聲如沸谷暮。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,357評論 0 19
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽湿弦。三九已至,卻和暖如春腾夯,著一層夾襖步出監(jiān)牢的瞬間颊埃,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,590評論 1 261
  • 我被黑心中介騙來泰國打工俯在, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留竟秫,地道東北人。 一個月前我還...
    沈念sama閱讀 45,636評論 2 355
  • 正文 我出身青樓跷乐,卻偏偏與公主長得像肥败,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子愕提,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 42,925評論 2 344

推薦閱讀更多精彩內(nèi)容