uni解决IOS暗黑模式的切换

tabbar的暗黑模式处理

首选需要开启ios 暗黑模式
uni 项目
在 “app-plus” -> “distribute” -> “ios” 节点下添加 UIUserInterfaceStyle 节点

// 在 "app-plus" -> "distribute" -> "ios" 节点下添加 UIUserInterfaceStyle 节点
"app-plus": {  
"distribute": {  
  "ios": {  
   "UIUserInterfaceStyle": "Automatic",  
    //...  
  },  
  //...  
},  
//...
// 代码位置 app.vue  项目入口的位置
onShow: function() {
			console.log('App Show')
			uni.onThemeChange(function (res) {
			    console.log(res.style, '模式');  
				var style = res.style
				
				if('dark'==style){  
				  console.log('当前为暗黑模式');  
								uni.setTabBarStyle({
								  color: '#fff',
								  backgroundColor: '#1B1C1E',
								  borderStyle: 'white'
								})
				}else{  
								  uni.setTabBarStyle({
								    color: '#9FA5AE',
								    selectedColor: '#486EE4',
								    backgroundColor: '#fff',
									 borderStyle: 'black'
								  })
				  console.log('当前为普通模式');  
				} 
			});
		},

解决页面中暗黑模式的切换

<style lang="scss">
	/*每个页面公共css */
		
		@media (prefers-color-scheme: dark) {
			page {
				background-color: #1B1C1E;
				color: white;
			}
		}
		
		
		@media (prefers-color-scheme: light) {
			page {
				background-color: #F7F7F7;
			}
		}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值