//自定义标签栏

    //第一个按钮

    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];

    firstButton.tag = 0;

    firstButton.frame = CGRectMake(0, ScreenHeight - 50, ScreenWidth/3, 50);

    [firstButton setBackgroundColor:[UIColor colorWithRed:38/225.f green:38/225.f blue:38/225.f alpha:1]];

    [firstButton setTitle:@"车票预订" forState:UIControlStateNormal];

    [firstButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [firstButton addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:firstButton];

    

    //第二个按钮

    UIButton *secondButton = [UIButton buttonWithType:UIButtonTypeCustom];

    secondButton.tag = 1;

    secondButton.frame = CGRectMake(ScreenWidth/3, ScreenHeight - 50, ScreenWidth/3, 50);

    [secondButton setBackgroundColor:[UIColor colorWithRed:38/225.f green:38/225.f blue:38/225.f alpha:1]];

    [secondButton setTitle:@"订单查询" forState:UIControlStateNormal];

    [secondButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [secondButton addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:secondButton];

    

    //第三个按钮

    UIButton *thirdButton = [UIButton buttonWithType:UIButtonTypeCustom];

    thirdButton.tag = 2;

    thirdButton.frame = CGRectMake(ScreenWidth/3 * 2, ScreenHeight - 50, ScreenWidth/3, 50);

    [thirdButton setBackgroundColor:[UIColor colorWithRed:38/225.f green:38/225.f blue:38/225.f alpha:1]];

    [thirdButton setTitle:@"我的12306" forState:UIControlStateNormal];

    [thirdButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

    [thirdButton addTarget:self action:@selector(changeLocation:) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:thirdButton];

    

    //透明按钮,用于显示被选中的效果

    _transparent = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight - 50, ScreenWidth/3, 50)];

    _transparent.backgroundColor = [UIColor whiteColor];

    _transparent.alpha = 0.2;

    [self.view addSubview:_transparent];

    

}

 

- (void)changeLocation:(UIButton*)sender{

    _transparent.frame = CGRectMake( ScreenWidth/3 * sender.tag, ScreenHeight - 50,ScreenWidth/3,50);

    NSInteger temp = _transparent.frame.origin.x/(ScreenWidth/3);

    //当前选中的ViewContorller

  self.selectedIndex = temp;

}

 --------------------------------------------------------------------------------

    buttonOfTime.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//左对齐的方法总结