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>