iOS导航栏配置问题

1:导航栏

//更改状态栏,但是需要加字段 View controller-based status bar appearance == NO 默认是YES

    //[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    //1.设置导航条的颜色

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

    //2.关闭导航条的毛玻璃效果.

//    self.navigationController.navigationBar.translucent = YES;

    //3.隐藏导航条

    self.navigationController.navigationBar.hidden = NO;

    //4.设置导航条内容的渲染颜色

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

    //5.设置导航条的背景图片.

    //图片尺寸不一样,显示的效果是不同的;(一定要非常严格)

    //    [self.navigationController.navigationBar setBackgroundImage:<#(UIImage *)#> forBarMetrics:<#(UIBarMetrics)#>];

    //6.设置导航条标题文字的大小和颜色

    NSDictionary *dic = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:18],                            NSForegroundColorAttributeName:[UIColor redColor]};

    self.navigationController.navigationBar.titleTextAttributes = dic;

2:

/**

 *  针对当前一个界面单独定制导航条内容

 */

- (void)customizedNavigationBarContent {

     //配置导航条上显示的标题

     self.navigationItem.title = @"第一个界面";

     //配置导航条的标题视图

     UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:@[@"国家", @"地区"]];

     self.navigationItem.titleView = segment;

     //配置左边内容,显示废纸篓按钮

     UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(handleTrash:)];      self.navigationItem.leftBarButtonItem = leftItem;

     //配置右边内容

     UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(handleAdd:)];

     self.navigationItem.rightBarButtonItem = rightItem;

 }

/**

 * //在对navigationBar进行设置时,比如添加一个scrollView,系统会自动将ScrollView下移偏离TOP 64个像素点,为了避免这样,我们有两种方法:

 1.将navigationBar的毛玻璃效果关闭;

 2.将navigationBar的属性automaticallyAdjustsScrollViewInsets = NO;

原文地址:https://www.cnblogs.com/guofuzhang/p/5269526.html