uni-app 动态设置 原生导航栏的button 原生导航栏字体图标显示为问号或方框的问题(自定义导航栏字体图标在IOS端是问号或方框)

uni-app原生导航栏字体图标变成问号

项目中向根据视频是否播放来控制导航栏中一个button是否显示,在一开始是这么写的

isPlay: {
    
    
	immediate: true,
	handler(isPlay) {
    
    
		//#ifdef APP-PLUS
		var currentWebview = this.$mp.page.$getAppWebview();
		if (isPlay) {
    
    
			currentWebview.setTitleNViewButtonStyle(3, {
    
    
				width: '60px'
			})
		} else {
    
    
			currentWebview.setTitleNViewButtonStyle(3, {
    
    
				width: '0'
			})
		}
		//#endif
	}
}

一开始在监听中是这样写的,在安卓中能正常跑,但是在ios端就出问题了。原生导航栏中的字体图标变成了问号
在这里插入图片描述
在网上想找解决方法也没又找到有效的,最后发现了监听这里可能会有问题,注释这段代码后就显示正常了,但还是需要监听button显示,所以换了写法。

isPlay: {
    
    
	immediate: true,
	handler(isPlay) {
    
    
		console.log('isPlay', isPlay)
		//#ifdef APP-PLUS
		var currentWebview = this.$mp.page.$getAppWebview();
		var tn = currentWebview.getStyle().titleNView;
		tn.buttons[3].text = isPlay ? "\ue607" : "";
		tn.buttons[3].background = isPlay ? "rgba(0,0,0,0.5)" : "rgba(0,0,0,0)"
		currentWebview.setStyle({
    
    
			titleNView: tn
		});
		//#endif
	}
}

最后,终于好了。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_45383558/article/details/106540873