iOS-系统自带navigationController-最全设置

 

    // 导航栏背景色

    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];

    // 设置push出来的controller返回按钮的箭头颜色

    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];

    

    // 设置push出来的controller返回按钮字体及颜色

    UIBarButtonItem *backItem=[[UIBarButtonItem alloc]init];

    backItem.title=@"BBBACK";

    [backItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor]} forState:UIControlStateNormal];

    self.navigationItem.backBarButtonItem = backItem;

    

    // 设置当前导航栏左右barbutton

    UIBarButtonItem *leftBarbutton = [[UIBarButtonItem alloc] initWithTitle:@"左按钮" style:UIBarButtonItemStylePlain target:self action:@selector(action:)];

    [leftBarbutton setTintColor:[UIColor blackColor]];

    [leftBarbutton setImage:[UIImage imageNamed:@"icon57.png"]];

    [leftBarbutton setTag:110];

    

    UIBarButtonItem *rightBartutton = [[UIBarButtonItem alloc] initWithTitle:@"右按钮" style:UIBarButtonItemStylePlain target:self action:@selector(action:)];

    [rightBartutton setTag:111];

    [rightBartutton setTintColor:[UIColor whiteColor]];

 

    self.navigationItem.rightBarButtonItem= rightBartutton;

    self.navigationItem.leftBarButtonItem = leftBarbutton;

    

    // 导航栏文字颜色

    //UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];

    //[navView setBackgroundColor:[UIColor whiteColor]];

    //[self.navigationItem setTitleView:navView];

    [self.navigationItem setTitle:@"主页"];

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

   

    // 视图坐标从导航栏高度开始

    [self.navigationController.navigationBar setTranslucent:NO];

 

    // 添加一个导航栏

    UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 70)];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"首页"];

    [navigationBar pushNavigationItem:navigationItem animated:NO];

    UIBarButtonItem *pushBarButton = [[UIBarButtonItem alloc] initWithTitle:@"左按钮" style:UIBarButtonItemStylePlain target:self action:@selector(push:)];

    [pushBarButton setTintColor:[UIColor blackColor]];

    [pushBarButton setImage:[UIImage imageNamed:@"icon57.png"]];

    navigationItem.rightBarButtonItem = pushBarButton;

    [self.view addSubview:navigationBar];

    // 设置其字体颜色和背景色

    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];

posted on 2015-10-29 14:18  XHShare  阅读(512)  评论(0编辑  收藏  举报

导航