微信小程序自定义顶部导航栏,动态适状态栏标题包括胶囊

微信小程序自定义顶部导航栏,动态适配包括胶囊

html 复制代码
<view>
	<uni-nav-bar :height="totalHeight" backgroundColor="#FFC003" leftWidth="100%">
			<block slot="left">
				<view>
					<view class="navTitle">
						哈哈哈
					</view>
				</view>
			</block>
		</uni-nav-bar>
</view>
javascript 复制代码
menu: [],
statusBarHeight: 0, //状态栏的高度 
navigatorHeight: 0, //导航栏高度
menuHeight: 0, //胶囊高度
menuTop: 0, //胶囊与顶部的距离
totalHeight: 0, //总高度 
onShow() {
	// 获取系统信息
	uni.getSystemInfo({
		success: res => {
			this.system = res;
			this.statusBarHeight = this.system.statusBarHeight; // 状态栏高度
			this.calculateNavBarHeight()
		}
	});
},
methods:{
	calculateNavBarHeight() {
		// 获取胶囊信息
		this.menu = uni.getMenuButtonBoundingClientRect();
		// 计算组件高度
		this.menuHeight = this.menu.height; // 胶囊高度
		this.menuTop = this.menu.top; // 胶囊与顶部的距离
		// 导航栏高度= (胶囊顶部距离-状态栏高度) x 2 + 胶囊的高度
		this.navigatorHeight = (this.menu.top - this.system.statusBarHeight) * 2 + this.menu.height;
		// 总高度 = 状态栏的高度 + 导航栏高度    
		this.totalHeight = this.statusBarHeight + this.navigatorHeight;
	 },
}
css 复制代码
	.navTitle {
		padding-left: 36rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 36rpx;
		color: #000000;
		margin-bottom: 10rpx;
	}
相关推荐
Emma歌小白3 天前
如何首次运行小程序后端
微信小程序
赣州云智科技的技术铺子3 天前
【一步步开发AI运动APP】十二、自定义扩展新运动项目1
微信小程序·小程序·云开发·智能小程序
2501_915918413 天前
iOS 上架全流程指南 iOS 应用发布步骤、App Store 上架流程、uni-app 打包上传 ipa 与审核实战经验分享
android·ios·小程序·uni-app·cocoa·iphone·webview
00后程序员张3 天前
iOS App 混淆与加固对比 源码混淆与ipa文件混淆的区别、iOS代码保护与应用安全场景最佳实践
android·安全·ios·小程序·uni-app·iphone·webview
破无差4 天前
《赛事报名系统小程序》
小程序·html·uniapp
00后程序员张4 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
海绵宝宝不喜欢侬4 天前
uniapp-微信小程序分享功能-onShareAppMessage
微信小程序·小程序·uni-app
2501_915106324 天前
Xcode 上传 ipa 全流程详解 App Store 上架流程、uni-app 生成 ipa 文件上传与审核指南
android·macos·ios·小程序·uni-app·iphone·xcode
亮子AI4 天前
【小程序】微信小程序隐私协议
微信小程序·小程序
weixin_177297220694 天前
短剧小程序系统开发:打造个性化娱乐新平台
小程序·娱乐·短剧