zoukankan      html  css  js  c++  java
  • iOS状态栏、导航栏的设置

    1、状态栏(statusBar)

    • 默认:黑色
    • 改变为白色:
    • 1.1 第一步:

      info.plist中添加View controller-based status bar appearance为NO
      
    • 1.2 第二步:

      [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
      

    2、导航栏的背景和文字Color:

    • 2.1 方法一:

      // 设置NavigationBar 背景颜色 & title 颜色  
      [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:20/255.0 green:155/255.0 blue:213/255.0 alpha:1.0]]; 
      
      [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];  
      
    • 2.2 方法二:

      // 设置NavigationBar背景颜色  
      [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];  
      
      // @{}代表Dictionary  
      [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];  
      

    3、导航栏使用背景图片:

    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];  
    

    4、取消导航栏按钮Item图片被渲染的效果

    • 4.1 方法一:通过代码设置

      image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
      
    • 4.2 方法二:通过Assets.xcassets设置

    • 找到对应图片的Image Set栏,Render as设置为Original Image.

    5、导航栏标题的字体:

    UITextAttributeFont - 字体
    UITextAttributeTextColor - 文字颜色
    UITextAttributeTextShadowColor - 文字阴影颜色
    UITextAttributeTextShadowOffset - 偏移用于文本阴影
    
    NSShadow *shadow = [[NSShadow alloc] init];  
    shadow.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8];  
    shadow.shadowOffset = CGSizeMake(0, 1);  
    
    // 任意颜色、字体大小、文字阴影颜色
    [[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:  [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName, shadow, NSShadowAttributeName,  
    [UIFont fontWithName:@"HelveticaNeue-CondensedBlack" size:21.0], NSFontAttributeName, nil nil]];  
    

    6、图片作为导航栏标题:

    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"appcoda-logo.png"]];  
    

    7、添加多个栏按钮项目:

    UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action: nil nil];  
    UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action: nil nil];  
    NSArray *itemsArr = @[shareItem,cameraItem];  
    self.navigationItem.rightBarButtonItems = itemsArr; 
    

    8、自定义后退按钮的文字和颜色:

    • 8.1 方法一:

      UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];  
      self.navigationItem.backBarButtonItem = item;  
      
      [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];  
      [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor redColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];  
      self.title = [NSString stringWithFormat:@"第%lu页",(unsigned long)self.navigationController.viewControllers.count];  
      
      //自定义返回按钮  
      UIImage *backButtonImage = [[UIImage imageNamed:@"fanhui.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 30, 0, 0)];  
      [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];  
      
      //将返回按钮的文字position设置不在屏幕上显示  
      [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(NSIntegerMin, NSIntegerMin) forBarMetrics:UIBarMetricsDefault];  
      
  • 相关阅读:
    Java的审计项目导入---基于现有的微服务项目上再加个xmsj
    vo中对date格式的时间格式的处理,方便到前台展示
    Java的Maven项目的导入
    [2020-05]测试短信发送记录
    那些年总是记不住的前端写法!
    【HTML+CSS】比较清淡的一个表格。
    C# 里这么写 busiDate.replace('-', ' ').trim(),可以把2020-04-01转为 20200401;java里这么些只能转为2020 04 01……
    radType条件没有用?
    我的程序里面出现了下面的警告:Unreachable code请问是什么原因?该怎么解决呢?
    ubuntu18.04安装Charles及问题
  • 原文地址:https://www.cnblogs.com/CH520/p/9551212.html
Copyright © 2011-2022 走看看