当前位置: 首页 > news >正文

赣州网站建设-赣州做网站免费推广软件下载

赣州网站建设-赣州做网站,免费推广软件下载,安阳做网站公司,wordpress文章存储uniapp vue3 使用 鸿蒙开源字体 我的需求是全局使用鸿蒙字体。 所以: 0. 首先下载鸿蒙字体: 鸿蒙资源 下载后解压,发现里面有几个文件夹: 字体名称说明Sans默认的鸿蒙字体,支持基本的多语言字符(包括字…

uniapp vue3 使用 鸿蒙开源字体

我的需求是全局使用鸿蒙字体。
所以:

0. 首先下载鸿蒙字体:

鸿蒙资源
在这里插入图片描述
下载后解压,发现里面有几个文件夹:

在这里插入图片描述

字体名称说明
Sans默认的鸿蒙字体,支持基本的多语言字符(包括字母、数字和部分中文)。
Sans_SC鸿蒙字体的简体中文版本,专门优化了简体中文字形。
Sans_TC鸿蒙字体的繁体中文版本,专门优化了繁体中文字形。
Sans_Italic鸿蒙字体的斜体版本,适用于字母和数字的斜体显示。
Sans_Condensed鸿蒙字体的压缩版本,适用于需要紧凑排版的场景。
Sans_Condensed_Italic鸿蒙字体的压缩斜体版本,适用于需要紧凑排版且斜体显示的场景。
Sans_Naskh_Arabic鸿蒙字体的阿拉伯语版本,专门优化了阿拉伯语字形。
Sans_Naskh_Arabic_UI鸿蒙字体的阿拉伯语 UI 版本,适用于用户界面的阿拉伯语显示。

如果你需要支持 简体中文 和 字母数字,应该使用以下字体:

HarmonyOS_Sans_SC.ttf:这是鸿蒙字体的简体中文版本,专门优化了简体中文字形,同时支持字母和数字。

1. 把字体文件放入目录

在这里插入图片描述

2. 写入App.vue

<script>
export default {onLaunch: function () {// console.log('App Launch')const fonts = [{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Thin.ttf', weight: 100 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Light.ttf', weight: 300 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Regular.ttf', weight: 400 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Medium.ttf', weight: 500 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Bold.ttf', weight: 700 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Black.ttf', weight: 900 },]fonts.forEach(font => {uni.loadFontFace({family: font.name,source: `url("${font.path}")`,weight: font.weight.toString(),success: () => {console.log(`字体 ${font.name} (${font.weight}) 加载成功`)},fail: (err) => {console.error(`字体 ${font.name} (${font.weight}) 加载失败`, err)}})})},onShow: function () {// console.log('App Show')},onHide: function () {// console.log('App Hide')}
}
</script><style lang="scss">
/* 引入 uview-plus 和 uni-scss */
@import "uview-plus/index.scss";
@import "uni_modules/uni-scss/index.scss";/* 引入鸿蒙字体的多字重 */
@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Thin.ttf') format('truetype');font-weight: 100; /* Thin */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Light.ttf') format('truetype');font-weight: 300; /* Light */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Regular.ttf') format('truetype');font-weight: 400; /* Regular */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Medium.ttf') format('truetype');font-weight: 500; /* Medium */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Bold.ttf') format('truetype');font-weight: 700; /* Bold */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Black.ttf') format('truetype');font-weight: 900; /* Black */
}/* 设置全局字体 */
page {font-family: 'HarmonyOS Sans', sans-serif;font-weight: 500; /* 默认使用 Medium字重 */background-color: #edf0f4; /* 页面背景色 */
}/* 设置 uview-plus 组件的默认字体 */
.u-page {font-family: 'HarmonyOS Sans', sans-serif;
}
</style>

预加载字体(可选)

为了确保字体加载成功,可以在 onLaunch 生命周期中使用 uni.loadFontFace 预加载字体。

<script>
export default {onLaunch: function () {// console.log('App Launch')const fonts = [{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Thin.ttf', weight: 100 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Light.ttf', weight: 300 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Regular.ttf', weight: 400 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Medium.ttf', weight: 500 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Bold.ttf', weight: 700 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Black.ttf', weight: 900 },]fonts.forEach(font => {uni.loadFontFace({family: font.name,source: `url("${font.path}")`,weight: font.weight.toString(),success: () => {console.log(`字体 ${font.name} (${font.weight}) 加载成功`)},fail: (err) => {console.error(`字体 ${font.name} (${font.weight}) 加载失败`, err)}})})},onShow: function () {// console.log('App Show')},onHide: function () {// console.log('App Hide')}
}
</script>

也可以在页面中使用字体

在具体的页面中,你可以直接使用 font-family: ‘HarmonyOS Sans SC’ 来应用字体。

<template><view class="container"><text class="text">这是一段测试文本(简体中文)</text><text class="text">Hello, 123456</text></view>
</template><script setup>
// 页面逻辑
</script><style scoped>
.container {padding: 20px;
}.text {font-family: 'HarmonyOS Sans SC', sans-serif;font-size: 16px;color: #333;
}
</style>

如果要兼容微信小程序

<script>
export default {onLaunch: function () {// 小程序环境动态加载字体// #ifdef MP-WEIXINconst fonts = [{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Thin.ttf', weight: 100 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Light.ttf', weight: 300 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Regular.ttf', weight: 400 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Medium.ttf', weight: 500 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Bold.ttf', weight: 700 },{ name: 'HarmonyOS Sans', path: '/static/fonts/HarmonyOS_Sans_SC_Black.ttf', weight: 900 },];fonts.forEach(font => {uni.loadFontFace({family: font.name,source: `url("${font.path}")`,weight: font.weight.toString(),success: () => {console.log(`字体 ${font.name} (${font.weight}) 加载成功`);},fail: (err) => {console.error(`字体 ${font.name} (${font.weight}) 加载失败`, err);}});});// #endif},onShow: function () {// console.log('App Show')},onHide: function () {// console.log('App Hide')}
}
</script><style lang="scss">
/* 引入 uview-plus 和 uni-scss */
@import "uview-plus/index.scss";
@import "uni_modules/uni-scss/index.scss";/* 引入鸿蒙字体的多字重 */
/* H5 环境直接使用 @font-face */
/* #ifdef H5 */
@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Thin.ttf') format('truetype');font-weight: 100; /* Thin */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Light.ttf') format('truetype');font-weight: 300; /* Light */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Regular.ttf') format('truetype');font-weight: 400; /* Regular */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Medium.ttf') format('truetype');font-weight: 500; /* Medium */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Bold.ttf') format('truetype');font-weight: 700; /* Bold */
}@font-face {font-family: 'HarmonyOS Sans';src: url('/static/fonts/HarmonyOS_Sans_SC_Black.ttf') format('truetype');font-weight: 900; /* Black */
}
/* #endif *//* 设置全局字体 */
page {font-family: 'HarmonyOS Sans', sans-serif;font-weight: 500; /* 默认使用 Medium 字重 */background-color: #edf0f4; /* 页面背景色 */
}/* 设置 uview-plus 组件的默认字体 */
.u-page {font-family: 'HarmonyOS Sans', sans-serif;
}
</style>

如果使用网络字体

@font-face {font-family: 'HarmonyOS Sans';src: url('https://your-domain.com/fonts/HarmonyOS_Sans_SC_Regular.ttf') format('truetype');font-weight: 400;
}
http://www.mmbaike.com/news/93225.html

相关文章:

  • 网站 建设 深圳aso应用商店优化原因
  • 营销型网站建设哪家好seo系统培训哪家好
  • 以下可以制作二维码的网站为近一周的新闻大事热点
  • 美食网网站建设目的无人区在线观看高清1080
  • 唐山开发网站的公司网页搜索关键词
  • 班级建设网站首页seo网站培训
  • 自己怎么做微信小程序网站北京营销网站制作
  • 上海b2b做网站58黄页网推广公司
  • 大连做网站比较好的官方推广平台
  • asp.net 网站管理工具新能源汽车公司
  • 跨境建站平台揭阳百度快照优化排名
  • 手表二级市场网站百度一下你就知道了
  • 怎么制作网站源码广告有限公司
  • 网站改版如何做301北京搜索引擎优化
  • 泉州专业网站设计技术公司灰色词快速排名方法
  • 南宁网站建设推广深圳网络营销推广渠道
  • 网络会议网站国内军事新闻最新消息
  • 浙江省嘉兴建设局官方网站网络市场营销
  • 广东海外建设监理有限公司网站卖链接的网站
  • 安徽网站建设制作seo网站关键词优化费用
  • 国内做电商网站seo技术顾问阿亮
  • 合肥网站开发 合肥网站优化老鬼seo
  • 网站建设技术交流教你如何建立网站
  • 怎样做自己的视频网站网站维护的主要内容
  • 阿里妈妈网站怎么做淘宝店铺运营推广
  • 如何做电子书下载网站建网站需要多少钱
  • 青岛网站建设的方案信息流广告怎么投放
  • 齐家网和土巴兔哪家好网站搜索引擎优化工具
  • 有什么网站可以做批发整站seo排名外包
  • 龙岩市建设局网站北京seo经理