uni-app picker-view的mask-style设置background时文字被隐藏
uni-app picker-view的mask-style设置background时文字被隐藏
| 开发环境 | 版本号 | 项目创建方式 |
|---|---|---|
| Windows | 11 | HBuilderX |
产品分类:uniapp/App
PC开发环境操作系统:Windows
HBuilderX类型:正式
HBuilderX版本号:4.45
手机系统:iOS
手机系统版本号:iOS 17
手机厂商:苹果
手机机型:iPhone15
页面类型:vue
vue版本:vue2
打包方式:云端
示例代码:
<picker-view class="u-picker__view" :indicatorStyle="height: ${addUnit(itemHeight, 'px')};"
value="innerIndex" mask-style="background:#141823" :immediateChange="immediateChange" :style="{
height: ${addUnit(visibleItemCount * itemHeight, 'px')}
}" @change="changeHandler">
<picker-view-column v-for="(item, index) in innerColumns" :key="index"
class="u-pickerviewcolumn">
<view v-if="testArray(item)" class="u-pickerviewcolumn__item u-line-1"
class="[index1 === innerIndex[index] && 'u-pickerviewcolumn__item--selected']"
v-for="(item1, index1) in item" :key="index1" :style="{
height: addUnit(itemHeight, 'px'),
lineHeight: addUnit(itemHeight, 'px'),
fontWeight: index1 === innerIndex[index] ? 'bold' : 'normal',
display: 'block',
}">{{ getItemText(item1) }}</view>
</picker-view-column>
</picker-view>
操作步骤:
<picker-view class="u-picker__view" :indicatorStyle="height: ${addUnit(itemHeight, 'px')};"
value="innerIndex" mask-style="background:#141823" :immediateChange="immediateChange" :style="{
height: ${addUnit(visibleItemCount * itemHeight, 'px')}
}" @change="changeHandler">
<picker-view-column v-for="(item, index) in innerColumns" :key="index"
class="u-pickerviewcolumn">
<view v-if="testArray(item)" class="u-pickerviewcolumn__item u-line-1"
class="[index1 === innerIndex[index] && 'u-pickerviewcolumn__item--selected']"
v-for="(item1, index1) in item" :key="index1" :style="{
height: addUnit(itemHeight, 'px'),
lineHeight: addUnit(itemHeight, 'px'),
fontWeight: index1 === innerIndex[index] ? 'bold' : 'normal',
display: 'block',
}">{{ getItemText(item1) }}</view>
</picker-view-column>
</picker-view>
预期结果:
只设置背景颜色为#141823,不影响文字显示
```实际结果:
mask-style设置background背景颜色时,会把每项item的文字给挡住,看不到文字。
```bug描述:
使用picker-view选择器,在mask-style设置background背景颜色时,会把每项item的文字给挡住。
更多关于uni-app picker-view的mask-style设置background时文字被隐藏的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复
更多关于uni-app picker-view的mask-style设置background时文字被隐藏的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这是因为mask-style设置的背景色覆盖了picker-view的文本内容。picker-view的遮罩层默认是半透明的,当设置不透明背景色时会完全遮挡内容。
解决方案:
- 使用
rgba设置带透明度的背景色:
mask-style="background:rgba(20,24,35,0.5)"
- 或者通过调整遮罩层透明度:
mask-style="background:#141823;opacity:0.5"
- 如果只需要修改选中区域样式,应该使用
indicator-style而非mask-style:
:indicator-style="{background:'#141823', height: addUnit(itemHeight, 'px')}"

