navigationItem的设置和titleView的设置

设置导航栏中间的标题

   self.navigationItem.title = @"title";

设置导航栏的主题颜色

self.navigationBar.barTintColor = [主题色];

设置导航栏的标题文字颜色

   [self.navigationController.navigationBar setBarTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor grayColor]}];

设置背景颜色

    [self.navigationBar setBarTintColor:[UIColor redColor]];

设置UIBarButtonItem的样式及图标颜色

    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(leftItemClick)];
        leftItem.tintColor=[UIColor grayColor];
    self.navigationItem.leftBarButtonItem = leftItem;

设置图片成为导航栏的标题

    UIImageView* imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"marker"]];
    self.navigationItem.titleView = imageView;

设置后退按钮的文字,和样式;

    /**
     UIBarButtonItemStylePlain,
     UIBarButtonItemStyleBordered NS_ENUM_DEPRECATED_IOS(2_0, 8_0, "Use UIBarButtonItemStylePlain when minimum deployment target is iOS7 or later"),
     UIBarButtonItemStyleDone,
     */

    UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backClick)];
    self.navigationItem.backBarButtonItem = backItem;

    //点击Cell跳转控制器

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UIViewController* VC = [[UIViewController alloc]init];
        [VC.view setFrame:[UIScreen mainScreen].bounds];
        VC.view.backgroundColor = [UIColor redColor];

    //设置返回按钮的颜色

       self.navigationController.navigationBar.tintColor=[UIColor grayColor];

        [self.navigationController pushViewController:VC animated:YES];
    }

//设置导航栏中title字体颜色及大小

    UILabel *LB = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    LB.text = @"ZCL";
    LB.font = [UIFont systemFontOfSize:8];
    LB.textColor = [UIColor redColor];
    //设置位置在中心
    LB.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = LB;

    //自定义导航栏(搜索框)
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
    searchBar.placeholder = @"输入科室进行查找";
    self.navigationItem.titleView = searchBar;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值