uni-app canvas文本溢出自动换行
发布时间
阅读量:
阅读量
封装
支持单行文本超出换行功能,实现多行文本的有序排列与展示
// 填充自动换行的文本
function fillFeedText({ctx, text, x, y, maxWidth, lineHeight, color, size}) {
// 文本配置
ctx.setFontSize(size);
ctx.setFillStyle(color);
ctx.setShadow(0, 0, 4, 'rgba(0, 0, 0, 0.5)');
ctx.fillStyle = '#FFFFFF'; // 填充颜色(黑色)
ctx.strokeStyle = '#FFFFFF'; // 边框颜色
ctx.lineWidth = 0.8; // 边框宽度
// 计算文本换行宽高,换行逻辑
const words = text.split('');
let line = '';
const lines = [];
for (let i = 0; i < words.length; i++) {
const word = words[i];
const testLine
全部评论 (0)
还没有任何评论哟~
