UINavigationBar的translucent、barTintColor、backgroundImage

本文详细探讨了在iOS中UINavigationBar的translucent、barTintColor和backgroundImage属性如何影响导航栏的背景效果。通过设置不同的组合,分析了translucent为NO、YES以及不主动设置时的情况,并提出了最佳实践和应用场景。
摘要由CSDN通过智能技术生成

 

| 导语 为了方便探讨,我把通过setBackgroundImage: forBarPosition: barMetrics:方法设置的image称为backgroundImage

translucent、barTintColor、backgroundImage三者共同决定了UINavigationBar的背景效果,而translucent在中间起非常关键的作用,它决定了系统如何使用barTintColor和backgroundImage去设置UINavigationBar的背景效果。

一、translucent设置为NO

如果translucent设置为NO,注意是“设置为NO”,也就是主动调用setter方法,这和“值为NO”有区别,区别在什么地方后面再讲。主动设置为NO,系统会怎样使用barTintColor和backgroundImage去设置UINavigationBar的背景效果呢?先看一下系统注释:

If you send setTranslucent:NO to a bar with a translucent custom background image 
it will provide an opaque background for the image using the bar's barTintColor if defined,
or black for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.

主要意思是,如果设置为NO,backgroundImage若是半透明的图

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值