微信小程序navigationBarTitleText不居中
时间: 2023-07-15 21:14:16 浏览: 279
如何实现微信小程序文字居中显示.doc
如果你在微信小程序中使用navigationBarTitleText设置导航栏标题,但是标题不居中,可以尝试以下方法:
1. 设置页面的样式为"navigationStyle":"custom",这样可以自定义导航栏样式。
2. 在导航栏中添加一个view,并设置该view的flex布局,使标题居中显示。
示例代码如下:
```
{
"navigationBarTitleText": "标题",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationStyle": "custom",
"usingComponents": {},
"backgroundTextStyle": "dark",
"backgroundColor": "#f8f8f8",
"enablePullDownRefresh": false,
"onReachBottomDistance": 50,
"navigationBarBackgroundColor": "#fff",
"navigationBarTextStyle": "black",
"navigationBarTitleText": "标题",
"backgroundTextStyle": "dark"
}
```
在页面的wxml文件中添加以下代码:
```
<view class="nav-title">{{navigationBarTitleText}}</view>
```
在页面的wxss文件中添加以下代码:
```
.nav-title {
display: flex;
justify-content: center;
align-items: center;
height: 100%;
font-size: 16px;
font-weight: bold;
}
```
通过以上方法,可以让标题居中显示。
阅读全文