当前位置: 首页 > news >正文

iOS7以上使导航栏半透明


1、nav bar的 translucent 设为YES。这个值默认就是YES的。
   如果translucent为NO,则导航栏一定是不透明的。
  [UINavigationBar appearance].translucent = YES;


2、用半透明的图设置BackgroundImage,设置了BackgroundImage后barTintColor就无效了。

  注意:这个图如果不够大,则会自动扩展到整个导航栏。

  UIImage* bg = ……;

   [[UINavigationBar appearance] setBackgroundImage:bg forBarMetrics:UIBarMetricsDefault];


下面是一个完整的例子:


//这一句可以没有,translucent 属性的默认值就是YES。
[UINavigationBar appearance].translucent = YES;
UIImage* bg = JDUtils.imageWithColor(COLORWithAlpha(0xea4940, 0.8));
[[UINavigationBar appearance] setBackgroundImage:bg forBarMetrics:UIBarMetricsDefault];


//由指定颜色生成一个像素大小的UIImage。
static UIImage* imageWithColor(UIColor * color)
{
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}      


//由16进制数成生UIColor的宏。
#define COLORWithAlpha(rgbValue,alphaValue) \
            [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
                            green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
                            blue:((float)(rgbValue & 0xFF))/255.0 \
                           alpha:alphaValue]

相关文章:

  • 过程建模EPC,我拿什么拯救你
  • 用图作背景的cell选中时背景图变暗
  • Guru.com - The world's largest online marketplace for freelance talent.
  • view controller的automaticallyAdjustsScrollViewInsets属性
  • Blog小技巧之三-在地图上显示访问Blog读者的分布信息
  • 简单的在工程中集成RAC
  • 10月8日培训日记
  • 聚合优于继承
  • 数据源变更时,table中更新对应cell的显示
  • Visual C# 2005 - 如何于DataGridView控件中以跨数据行方式显示数据
  • iPhone在设置中修改应用相关项,应用会重启
  • 10月9日培训日记
  • 编译蘑菇街的teamtalk
  • HTML框架代码全集
  • 同一bundle id的应用,不同证书在设备上覆盖安装会失败
  • 《深入 React 技术栈》
  • 【翻译】Mashape是如何管理15000个API和微服务的(三)
  • iOS | NSProxy
  • Java 最常见的 200+ 面试题:面试必备
  • laravel with 查询列表限制条数
  • mysql innodb 索引使用指南
  • spring + angular 实现导出excel
  • WinRAR存在严重的安全漏洞影响5亿用户
  • 服务器从安装到部署全过程(二)
  • 检测对象或数组
  • 聊聊flink的TableFactory
  • 前端每日实战:70# 视频演示如何用纯 CSS 创作一只徘徊的果冻怪兽
  • 说说动画卡顿的解决方案
  • 项目实战-Api的解决方案
  • Salesforce和SAP Netweaver里数据库表的元数据设计
  • 阿里云ACE认证学习知识点梳理
  • 大数据全解:定义、价值及挑战
  • 函数计算新功能-----支持C#函数
  • 正则表达式-基础知识Review
  • ​第20课 在Android Native开发中加入新的C++类
  • #pragma data_seg 共享数据区(转)
  • (2)(2.4) TerraRanger Tower/Tower EVO(360度)
  • (WSI分类)WSI分类文献小综述 2024
  • (动手学习深度学习)第13章 计算机视觉---微调
  • (二)什么是Vite——Vite 和 Webpack 区别(冷启动)
  • (南京观海微电子)——I3C协议介绍
  • (转)Android学习系列(31)--App自动化之使用Ant编译项目多渠道打包
  • (转)iOS字体
  • *++p:p先自+,然后*p,最终为3 ++*p:先*p,即arr[0]=1,然后再++,最终为2 *p++:值为arr[0],即1,该语句执行完毕后,p指向arr[1]
  • .net core控制台应用程序初识
  • .Net6 Api Swagger配置
  • .NET应用架构设计:原则、模式与实践 目录预览
  • .NET中winform传递参数至Url并获得返回值或文件
  • /usr/local/nginx/logs/nginx.pid failed (2: No such file or directory)
  • @DataRedisTest测试redis从未如此丝滑
  • [ vulhub漏洞复现篇 ] ThinkPHP 5.0.23-Rce
  • [<事务专题>]
  • [acwing周赛复盘] 第 94 场周赛20230311
  • [CLR via C#]11. 事件
  • [daily][archlinux][game] 几个linux下还不错的游戏