小程序中圆角边框的设置

与CSS一样,小程序中的圆角可以通过border-radius来设置。
以input为例,想要设置圆角边框,只需加上如下样式:

 border-radius: 5px

即可实现如下效果:
这里写图片描述
不同的是,在小程序中想要设置仅其中某个圆角,而其它为直角,则需要使用 border-bottom-left-radius, border-top-left-radius, border-bottom-left-radius, border-top-left-radius单独设置,使用类似于CSS中的直接在border-radius属性中写四个值,如: border-radius: 5px,0px,0px,5px; 则没有效果
这里写图片描述
以下是设置左半边为圆角,右半边为直角的情况:

 border-bottom-left-radius: 5px;
 border-top-left-radius: 5px;

这里写图片描述
另外,小程序中按钮button是自带圆角的,
这里写图片描述
因此如果想设置仅一半显示圆角,需如下设置:

 border-radius: 0px;
 border-bottom-right-radius: 5px;
 border-top-right-radius: 5px;

效果如下:
这里写图片描述
据此我们可以生成一个带圆角边框的搜索栏:
这里写图片描述
wxml

   <view class="search-cell">
      <view class="weui-cell__bd">
        <input class="input-search" placeholder=""  value="{{inputVal}}"/>
      </view>
      <view class="weui-cell__ft">
        <button class="btn-search" type="primary" >搜索</button>
      </view>
    </view>

wxss

.btn-search {
  border-radius: 0px;
  border-bottom-right-radius: 5px;
  border-top-right-radius: 5px;
  font-size: 13px;
  font-family: "微软雅黑";
}
.input-search {
  border: lightgrey;
  border-style: solid;
  border-width: 1px;
  font-size: 14px;
  border-bottom-left-radius: 5px;
  border-top-left-radius: 5px;
  height: 31px;
  padding-left: 10px;
}
.search-cell {
  margin-top: 30px;
  position: relative;
  display: -webkit-box;
  display: -webkit-flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
  align-items: center;
}

当然对于本身不带边框的组件,如label,view等,注意要配合border属性使用才能显示出圆角边框的效果。

### 设置微信小程序 TabBar 边框圆角 为了实现微信小程序中的自定义 TabBar 并使其具有圆角边框效果,可以采用 UniApp 提供的方法来创建自定义组件[^1]。需要注意的是,在 H5 端之外,这种做法可能会带来一定的性能损失,因此除非有特殊需求,通常建议优先考虑使用默认的 TabBar 组件。 对于希望实现圆形边框的情况,可以通过 CSS 样式控制来自定义 TabBar 的外观。具体来说: #### 修改 `app.json` 文件配置 首先需要禁用默认的小程序底部导航栏,并开启自定义 tabBar 功能: ```json { "tabBar": { "custom": true, ... } } ``` #### 创建自定义 TabBar 组件 接着构建一个新的 Vue 组件作为自定义 tabBar 使用。在这个过程中,通过编写 HTML 和 SCSS 来设计所需的布局与样式,特别是要应用 border-radius 属性给容器元素以达到圆角的效果[^2]: ```scss /* 自定义 tabBar 样式 */ .tab-bar-container { display: flex; justify-content: space-around; align-items: center; padding: 8px 0; background-color: white; box-shadow: 0 -2px 6px rgba(0, 0, 0, .1); border-top-left-radius: 16px; /* 左上角圆角 */ border-top-right-radius: 16px; /* 右上角圆角 */ } .tab-item { flex-grow: 1; text-align: center; font-size: 14px; } ``` #### 解决可能遇到的问题 当实现了上述更改之后,如果发现存在页面切换时 tabbar 出现闪烁现象,则可以在各个页面的 onLoad 或者 onShow 方法内调用 getTabBar 接口重新设定选中项的状态,从而避免此类问题的发生[^3]: ```javascript // 页面加载完成后的回调函数 onLoad() {} // 页面显示/切入前台时触发 onShow() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: getCurrentPages().pop().route.indexOf('index') !== -1 ? 0 : 1 // 假设首页索引为0 }) } }, ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值