深圳响应式网站开发,免费网络电视直播软件,wordpress怎么添加二级,西柳网站建设一、组件介绍 组件#xff08;Component#xff09;是界面搭建与显示的最小单位#xff0c;HarmonyOS ArkUI声名式为开发者提供了丰富多样的UI组件#xff0c;我们可以使用这些组件轻松的编写出更加丰富、漂亮的界面。 组件根据功能可以分为以下五大类#xff1a;基础组件…一、组件介绍 组件Component是界面搭建与显示的最小单位HarmonyOS ArkUI声名式为开发者提供了丰富多样的UI组件我们可以使用这些组件轻松的编写出更加丰富、漂亮的界面。 组件根据功能可以分为以下五大类基础组件、容器组件、媒体组件、绘制组件、画布组件。其中基础组件时视图层的基本组成单位包括Text、Image、TextInput、Buttton、LoadingProgress等。
下面我们将分别介绍这些常用基础组件的使用 Text
Text组件用于在界面上展示一段文本信息可以包含子组件Span。
文本样式 针对包含文本元素的组件例如Text、Span、Button、TextInput等可使用fontColor、fontSize、fontStyle、 fontWeight、fontFamily这些文本样式分别设置文本的颜色、大小、样式、粗细以及字体文本样式的属性如下表 名称 参数类型 描述 fontColor ResourceColor 设置文本颜色。 fontSize Length | Resource 设置文本尺寸Length为number类型时使用fp单位。 fontStyle FontStyle 设置文本的字体样式。默认值FontStyle.Normal。 fontWeight number | FontWeight | string 设置文本的字体粗细number类型取值[100, 900]取值间隔为100默认为400取值越大字体越粗。string类型仅支持number类型取值的字符串形式例如“400”以及“bold”、“bolder”、“lighter”、“regular”、“medium”分别对应FontWeight中相应的枚举值。默认值FontWeight.Normal。 fontFamily string | Resource 设置文本的字体列表。使用多个字体使用“”进行分割优先级按顺序生效。例如“Arialsans-serif”。
示例代码中包含两个Text组件第一个使用的是默认样式第二、三个自己给文本设置了一些文本样式。
Entry
Component
struct Index {State message: string Hello World;build() {Row() {Column() {Text(HarmonyOS)Text(HarmonyOS).fontColor(Color.Red).fontSize(22).fontStyle(FontStyle.Italic).fontWeight(FontWeight.Bold).fontFamily(Arial)Text(HarmonyOS).fontColor(Color.Green).fontSize(26).fontStyle(FontStyle.Normal).fontWeight(700).fontFamily(sans-serif)}.width(100%)}.height(100%)}
}2、设置文本对齐方式
使用textAlign属性可以设置文本的对齐方式示例代码如下
Entry
Component
struct Index {State message: string Hello World;build() {Row() {Column() {Text(HarmonyOS).width(200).backgroundColor(Color.Yellow).textAlign(TextAlign.Start)Text(HarmonyOS).fontColor(Color.Red).fontSize(22).fontStyle(FontStyle.Italic).fontWeight(FontWeight.Bold).fontFamily(Arial).width(200).margin({ top: 12 }).backgroundColor(Color.Yellow).textAlign(TextAlign.Center)Text(HarmonyOS).fontColor(Color.Green).fontSize(26).fontStyle(FontStyle.Normal).fontWeight(700).fontFamily(sans-serif).width(200).margin({ top: 12 }).backgroundColor(Color.Yellow).textAlign(TextAlign.End)}.width(100%)}.height(100%)}
}textAlign参数类型为TextAlign定义了以下几种类型
Start默认值水平对齐首部。 Center水平居中对齐。 End水平对齐尾部。 3、设置文本超长显示 当文本内容较多超出了Text组件范围的时候您可以使用textOverflow设置文本截取方式需配合maxLines使用单独设置不生效maxLines用于设置文本显示最大行数。下面的示例代码将textOverflow设置为Ellipsis 它将显示不下的文本用 “...” 表示
Entry
Component
struct Index {State message: string Hello World;build() {Row() {Column() {Text(This is the text content of Text Component This is the text content of Text Component)Blank(10)Text(This is the text content of Text Component This is the text content of Text Component).fontSize(16).maxLines(1).textOverflow({ overflow: TextOverflow.Ellipsis }).backgroundColor(0xE6F2EE)}.width(100%)}.height(100%)}
}效果图如下 4、设置文本装饰线 使用decoration设置文本装饰线样式及其颜色大家在浏览网页的时候经常可以看到装饰线例如带有下划线超链接文本。 decoration包含type和color两个参数其中type用于设置装饰线样式参数类型为TextDecorationTypcolor为可选参数。
下面的示例代码给文本设置了下划线下划线颜色为黑色
Entry
Component
struct Index {State message: string Hello World;build() {Row() {Column() {Text(HarmonyOS).fontSize(20).decoration({ type: TextDecorationType.Underline, color: Color.Black }).backgroundColor(Color.Gray)}.width(100%)}.height(100%)}
}效果图如下 TextDecorationTyp包含以下几种类型
None不使用文本装饰线。 .decoration({ type: TextDecorationType.None, color: Color.Red }) Overline文字上划线修饰。
.decoration({ type: TextDecorationType.Overline, color: Color.Red }) LineThrough穿过文本的修饰线。
.decoration({ type: TextDecorationType.LineThrough, color: Color.Red }) Underline文字下划线修饰。
.decoration({ type: TextDecorationType.Underline, color: Color.Red })