1***@163.com
1***@163.com
  • 发布:2024-12-05 14:06
  • 更新:2025-08-19 15:39
  • 阅读:252

IOS端 canvas 绘制字体加粗不生效,H5,安卓端正常

分类:uni-app

IOS端 canvas 绘制字体加粗不生效,H5,安卓端正常

context.font = 'bold 16px Arial'; H5 安卓端都正常加粗
只有ios端无效

2024-12-05 14:06 负责人:无 分享
已邀请:
DCloud_UNI_OttoJi

DCloud_UNI_OttoJi - 日常回复 uni-app/x 问题,如果艾特我没看到,请主动私信

提供下完整页面源码,并说明 vue 和HBuilderX 版本,方便我测试和验证问题。你测试了几台 ios 设备,模拟器、不同版本的真机表现都不能加粗吗

<template>  
  <view>  
    <canvas style="width: 100%; height: 200px;border:1px solid red" canvas-id="firstCanvas" id="firstCanvas"></canvas>  
  </view>  
</template>  

<script>  
  export default {  
    data() {  
      return {  
        ctx: null  
      }  
    },  
    onReady() {  
      this.ctx = uni.createCanvasContext('firstCanvas')  
      const ctx = this.ctx  

      let marginLeft = 10;  
      let boxWidth = 375  
      let centerX = boxWidth / 2;  
      let marginTop = 10  

      // 设置字体:bold 28px Arial  
      ctx.font = "bold " + Math.round(28) + "px Arial";  

      // 设置文字颜色  
      ctx.setFillStyle('#000000');  

      // 绘制文字  
      ctx.fillText("Hello UniApp Canvas!", 50, 100);  

      // 执行绘制  
      ctx.draw();  
    }  
  }  
</script>

使用上面 demo 对比安卓和 ios 模拟器没有明显差异。

  • 2***@qq.com

    4.75最新版本ctx.font = "bold " + Math.round(28) + "px Arial";

    2025-08-19 12:56

  • DCloud_UNI_OttoJi

    回复 2***@qq.com: 我补充了 demo,你拍一下对比差异

    2025-08-19 15:40

要回复问题请先登录注册