鸿蒙HarmonyOS实战-ArkUI组件(Text Span)_鸿蒙中text和span的区别是什么

Column() {
Text() {
Span(‘我是Span1,’).fontSize(16).fontColor(Color.Grey)
.decoration({ type: TextDecorationType.LineThrough, color: Color.Red })
Span(‘我是Span2’).fontColor(Color.Blue).fontSize(16)
.fontStyle(FontStyle.Italic)
.decoration({ type: TextDecorationType.Underline, color: Color.Black })
Span(‘,我是Span3’).fontSize(16).fontColor(Color.Grey)
.decoration({ type: TextDecorationType.Overline, color: Color.Green })
}
.borderWidth(1)
.padding(10)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋2.3 textCase

textCase设置文字一直保持大写或者小写状态

@Entry
@Component
struct Index {
build() {
Column() {
Text() {
Span(‘I am Upper-span’).fontSize(12)
.textCase(TextCase.UpperCase).onClick(()=>{
console.info(‘我是Span——onClick’)
})
}
.borderWidth(1)
.padding(10)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

3.自定义文本样式

🦋3.1 textAlign

textAlign属性用于设置文本在其容器中的水平对齐方式。

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘左对齐’)
.width(300)
.textAlign(TextAlign.Start)
.border({ width: 1 })
.padding(10)
Text(‘中间对齐’)
.width(300)
.textAlign(TextAlign.Center)
.border({ width: 1 })
.padding(10)
Text(‘右对齐’)
.width(300)
.textAlign(TextAlign.End)
.border({ width: 1 })
.padding(10)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋3.2 textOverflow

textOverflow属性是添加的一个文本溢出属性,用于标识当元素的文本溢出其指定大小的容器时如何处理。textOverflow需配合maxLines一起使用(默认情况下文本自动折行)

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘This is the setting of textOverflow to Clip text content This is the setting of textOverflow to None text content. This is the setting of textOverflow to Clip text content This is the setting of textOverflow to None text content.’)
.width(250)
.textOverflow({ overflow: TextOverflow.None })
.maxLines(1)
.fontSize(12)
.border({ width: 1 }).padding(10)
Text(‘我是超长文本,超出的部分显示省略号。I am an extra long text, with ellipses displayed for any excess。’)
.width(250)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.maxLines(1)
.fontSize(12)
.border({ width: 1 }).padding(10)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋3.3 lineHeight

lineHeight属性用于设置行高,即每行文本的高度。它可以用于任何元素,包括块级元素、行内元素和表格单元

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘This is the text with the line height set. This is the text with the line height set.’)
.width(300).fontSize(12).border({ width: 1 }).padding(10)
Text(‘This is the text with the line height set. This is the text with the line height set.’)
.width(300).fontSize(12).border({ width: 1 }).padding(10)
.lineHeight(20)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋3.4 decoration

decoration属性设置文本装饰线样式及其颜色,前面span介绍过就不介绍了

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘This is the text’)
.decoration({
type: TextDecorationType.LineThrough,
color: Color.Red
})
.borderWidth(1).padding(10).margin(5)
Text(‘This is the text’)
.decoration({
type: TextDecorationType.Overline,
color: Color.Red
})
.borderWidth(1).padding(10).margin(5)
Text(‘This is the text’)
.decoration({
type: TextDecorationType.Underline,
color: Color.Red
})
.borderWidth(1).padding(10).margin(5)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋3.5 baselineOffset

baselineOffset属性是用于控制行内元素基线位置的属性。它可以将元素相对于其父元素的基线位置向上或向下移动指定的距离,以满足垂直对齐的需求。该属性接受长度或百分比值作为参数。正值会将元素向上移动,负值会将元素向下移动。当使用百分比值时,该值会相对于元素自身的 fontSize 计算。

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘This is the text content with baselineOffset 0.’)
.baselineOffset(0)
.fontSize(12)
.border({ width: 1 })
.padding(10)
.width(‘100%’)
.margin(5)
Text(‘This is the text content with baselineOffset 30.’)
.baselineOffset(30)
.fontSize(12)
.border({ width: 1 })
.padding(10)
.width(‘100%’)
.margin(5)

Text(‘This is the text content with baselineOffset -20.’)
.baselineOffset(-20)
.fontSize(12)
.border({ width: 1 })
.padding(10)
.width(‘100%’)
.margin(5)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋3.6 letterSpacing

letterSpacing属性用于设置文本中字母之间的间距。它可以接受一个值,这个值可以是小于或大于0的数字,也可以是正负百分比数值。正值会增加字符之间的距离,而负值则会减小它们之间的距离。如果没有使用该属性,字母之间的默认间距将由系统决定。

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘This is the text content with letterSpacing 0.’)
.letterSpacing(0)
.fontSize(12)
.border({ width: 1 })
.padding(10)
.width(‘100%’)
.margin(5)
Text(‘This is the text content with letterSpacing 3.’)
.letterSpacing(3)
.fontSize(12)
.border({ width: 1 })
.padding(10)
.width(‘100%’)
.margin(5)
Text(‘This is the text content with letterSpacing -1.’)
.letterSpacing(-1)
.fontSize(12)
.border({ width: 1 })
.padding(10)
.width(‘100%’)
.margin(5)
}.width(‘100%’).height(‘100%’)
}
}

在这里插入图片描述

🦋3.7 minFontSize与maxFontSize

minFontSize和maxFontSize是用于设置文本字体大小的属性。这两个属性指定了一个范围,使得当文本的尺寸调整时,字体大小的最小值不会小于minFontSize,最大值不会大于maxFontSize。这些属性通常与viewport相关,因为文本大小可能需要在不同的屏幕尺寸和分辨率下进行调整。

@Entry
@Component
struct Index {
build() {
Column() {
Text(‘我的最大字号为30,最小字号为5,宽度为250,maxLines为1’)
.width(250)
.maxLines(1)
.maxFontSize(30)
.minFontSize(5)
.border({ width: 1 })
.padding(10)
.margin(5)
Text(‘我的最大字号为30,最小字号为5,宽度为250,maxLines为2’)
.width(250)
.maxLines(2)
.maxFontSize(30)
.minFontSize(5)
.border({ width: 1 })
.padding(10)
.margin(5)
Text(‘我的最大字号为30,最小字号为15,宽度为250,高度为50’)
.width(250)
.height(50)
.maxFontSize(30)
.minFontSize(15)
.border({ width: 1 })
.padding(10)
.margin(5)
Text(‘我的最大字号为30,最小字号为15,宽度为250,高度为100’)
.width(250)
.height(100)
.maxFontSize(30)

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数HarmonyOS鸿蒙开发工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年HarmonyOS鸿蒙开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上HarmonyOS鸿蒙开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新

如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注鸿蒙获取)
img

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上HarmonyOS鸿蒙开发知识点,真正体系化!**

由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新

如果你觉得这些内容对你有帮助,可以添加VX:vip204888 (备注鸿蒙获取)
[外链图片转存中…(img-cxV9rskg-1712809641478)]

一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值