UI 设计规范


如何使用
本地引入依赖
在使用方的 oh-package.json5
文件中添加如下代码依赖
1 2 3
| "dependencies": { "@ohos/uikit": "file:../uikit" }
|
Import 导入
导入所需的库内容,在使用的 .ets
文件内添加如下代码内容
1 2 3 4 5 6 7 8 9
| import { YCUIButton, YCUIButtonConfig, YCUIButtonArrowType, YCUIButtonBackgroundType, YCUIButtonColorType, YCUIButtonConfigSizeType, YCUIButtonCornerType } from '@ohos/uikit'
|
基础使用代码示例
这里演示了基本使用方法,以及点击后按钮的动态修改效果:初始黄色样式按钮,点击后变为红色样式,文案跟随改变,如此循环往复
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| @Entry @Component struct Index { @State buttonConfig: YCUIButtonConfig = new YCUIButtonConfig()
aboutToAppear(): void { this.buttonConfig.sizeType = YCUIButtonConfigSizeType.HUGE this.buttonConfig.backgroundType = YCUIButtonBackgroundType.SHADING this.buttonConfig.arrowType = YCUIButtonArrowType.RIGHT_ARROW this.buttonConfig.title = '短笛大魔王' }
build() { Row() { YCUIButton({config: this.buttonConfig, onTapClicked: () => { console.debug('点击了' + this.buttonConfig.title) if (this.buttonConfig.title == '短笛大魔王') { this.buttonConfig.colorType = YCUIButtonColorType.RED this.buttonConfig.title = '悟天克斯' } else { this.buttonConfig.colorType = YCUIButtonColorType.YELLOW this.buttonConfig.title = '短笛大魔王' } console.debug('buttonConfig.colorType =' + this.buttonConfig.colorType) } }) .height(45) .margin(120) } }
|
运行效果
点击前

点击后

代码解释
首先我们需要声明一个配置文件 YCUIButtonConfig
,配置文件的内容决定了 YCUIButton
的展示样式。同时我们可以随时修改配置文件,YCUIButton
会自动根据配置文件的内容进行样式修改和更新。
1 2
| @State buttonConfig: YCUIButtonConfig = new YCUIButtonConfig()
|
其次,我们需要在页面声明周期开始时,也就是 aboutToAppear
阶段对配置内容进行初始化,下面的示例我们只修改了 sizeType
、backgroundType
和arrowType
三项配置,其余均采用 UI 组件设计规范中默认的样式。
1 2 3 4 5 6 7
| aboutToAppear(): void { this.buttonConfig.sizeType = YCUIButtonConfigSizeType.HUGE this.buttonConfig.backgroundType = YCUIButtonBackgroundType.SHADING this.buttonConfig.arrowType = YCUIButtonArrowType.RIGHT_ARROW this.buttonConfig.title = '短笛大魔王' }
|
最后,我们在 build
中构建我们的 YCUIButton
,用法与系统 Button 基本一致。
只需要传入一个title
和我们此前声明的 YCUIButtonConfig
即可,同时提供了可选的单机回调onTapClicked
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| build() { Row() { YCUIButton({config: this.buttonConfig, onTapClicked: () => { console.debug('点击了' + this.buttonConfig.title) if (this.buttonConfig.title == '短笛大魔王') { this.buttonConfig.colorType = YCUIButtonColorType.RED this.buttonConfig.title = '悟天克斯' } else { this.buttonConfig.colorType = YCUIButtonColorType.YELLOW this.buttonConfig.title = '短笛大魔王' } console.debug('buttonConfig.colorType =' + this.buttonConfig.colorType) } }) .height(45) .margin(120) } }
|
自定义按钮颜色
某些需求可能要求使用超出组件 UI 设计规范(MasterGo - UI 组件规范设计稿)的色值,此时需要对色值进行自定义
1 2 3 4 5 6 7 8 9
| aboutToAppear(): void { this.buttonConfig.colorType = YCUIButtonColorType.CUSTOM this.buttonConfig.customBGColor = '#393548' this.buttonConfig.customFontColor = '#FFFFFF' this.buttonConfig.customBorderColor = Color.Red this.buttonConfig.title = '自定义按钮' }
|
API
配置参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| title: string = ''
sizeType: YCUIButtonConfigSizeType = YCUIButtonConfigSizeType.MIDDLE
cornerType: YCUIButtonCornerType = YCUIButtonCornerType.RADIUS_HALF
backgroundType: YCUIButtonBackgroundType = YCUIButtonBackgroundType.PURE
arrowType: YCUIButtonArrowType = YCUIButtonArrowType.NONE
colorType: YCUIButtonColorType = YCUIButtonColorType.YELLOW
customBGColor: ResourceColor = Color.Transparent
customFontColor: ResourceColor = Color.Transparent
customBorderColor: ResourceColor = Color.Transparent
|
按钮尺寸类型
1 2 3 4 5 6 7 8 9 10 11 12 13
|
export enum YCUIButtonConfigSizeType { HUGE = 3, LARGE = 1, MIDDLE = 0, SMALL = 2 }
|
按钮圆角类型
1 2 3 4 5 6 7 8 9 10 11 12 13
|
export enum YCUIButtonCornerType { RADIUS4 = 1, RADIUS_HALF = 0, RADIUS_HALF_BORDER_BOLD = 2, RADIUS_HALF_BORDER_REGULAR = 3 }
|
按钮背景类型
1 2 3 4 5 6 7 8 9
|
export enum YCUIButtonBackgroundType { PURE = 0, SHADING = 1 }
|
按钮箭头类型
1 2 3 4 5 6 7 8 9
|
export enum YCUIButtonArrowType { NONE = 0, RIGHT_ARROW = 1 }
|
按钮颜色类型
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
export enum YCUIButtonColorType { YELLOW = 0, BLUE = 1, RED = 2, WHITE = 3, DARK = 4, GRAY = 5, WHITE_RED = 6, CUSTOM = 7 }
|
点击回调
1 2 3 4
|
public onTapClicked?: () => void
|
加载 HUD - YCUILoading
使用非常简单,包含了 loading、success、error、info、progress 等样式效果
注意事项:受第三方库限制,使用时需要将 lottie 的 json文件放入 lottie 文件夹
并加入到 scr/main/ets
路径下与 pages 文件夹
同级别的目录中,否则无法识别 lottie 资源文件
如何使用
本地引入依赖
在使用方的 oh-package.json5
文件中添加如下代码依赖
1 2 3
| "dependencies": { "@ohos/uikit": "file:../uikit" }
|
Import 导入
导入所需的库内容,在使用的 .ets
文件内添加如下代码内容
1 2 3
| import { YCUILoading } from '@ohos/uikit'
|
Loading
1 2 3 4 5 6 7 8 9
| YCUILoading.showLoading()
YCUILoading.showLoading('正在努力加载')
YCUILoading.hide()
YCUILoading.showLoading('正在努力加载', true)
|
Toast
1 2 3 4 5 6 7 8 9 10
| YCUILoading.showSuccess('充值成功')
YCUILoading.showFailure('点赞失败,请检查网络')
YCUILoading.showInfo('你指尖跳动的电光,是我永恒不变的信仰。\n 唯我超电磁炮永世长存。!\n\n あなたの指先の跃动する电光は、私の一生変わらない信仰である')
YCUILoading.showSuccess('充值成功', true)
|
Progress
1 2 3 4 5
| YCUILoading.showProgress('正在下载中...')
YCUILoading.showProgress('正在下载中...', true)
|
LoadingSettings
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| export interface LoadingSettings {
msg?: string
alignment?: DialogAlignment
offset?: Offset
tintColor?: ResourceColor
textColor?: ResourceColor
hideDelay?: number
fontSize?: number | string | Resource
backgroundColor?: ResourceColor
maskColor?: ResourceColor
borderRadius?: Length | BorderRadiuses
successSrc?: PixelMap | ResourceStr | DrawableDescriptor
failureSrc?: PixelMap | ResourceStr | DrawableDescriptor }
|
导航栏 - YCUINavigationBar
本地引入依赖
在使用方的 oh-package.json5
文件中添加如下代码依赖
1 2 3
| "dependencies": { "@ohos/uikit": "file:../uikit" }
|
Import 导入
导入所需的库内容,在使用的 .ets
文件内添加如下代码内容
1 2 3 4
| import { YCUINavigationBar, YCUINavigationBarConfig } from '@ohos/uikit'
|
基础使用代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| @Entry @Component struct UIKitPage {
@State navigationConfig: YCUINavigationBarConfig = new YCUINavigationBarConfig()
aboutToAppear(): void { this.navigationConfig.title = '导航栏标题' this.navigationConfig.underlineVisibility = Visibility.Visible this.navigationConfig.jumpButtonVisibility = Visibility.Visible }
onPageShow(): void { YCScreenUtils.setWindowLayoutFullScreen(true) }
@Builder navigationBar() { YCUINavigationBar({ config: this.navigationConfig, onBackClicked: () => { console.debug('点击了返回') }, onRightClicked: () => { console.debug('点击了右侧按钮') } }) .width('100%') .height('100vp') .position({x: 0, y: 0}) .backgroundColor(Color.White) }
build() { Column() { this.navigationBar() } .width('100%') .height('100%') } }
|
运行效果

代码解释
首先我们需要声明一个配置文件 YCUINavigationBarConfig
,配置文件的内容决定了 YCUINavigationBar
的展示样式。同时我们可以随时修改配置文件,YCUINavigationBar
会自动根据配置文件的内容进行样式修改和更新。
1 2
| @State navigationConfig: YCUINavigationBarConfig = new YCUINavigationBarConfig()
|
其次,我们需要在页面声明周期开始时,也就是 aboutToAppear
阶段对配置内容进行初始化,下面的示例我们只修改了 title
、underlineVisibility
和jumpButtonVisibility
三项配置,其余均采用 UI 组件设计规范中默认的样式。
1 2 3 4 5 6 7 8 9
| aboutToAppear(): void { this.navigationConfig.title = '导航栏标题' this.navigationConfig.underlineVisibility = Visibility.Visible this.navigationConfig.jumpButtonVisibility = Visibility.Visible }
|
最后,我们在 build
中构建我们的 YCUINavigationBar
,用法与系统 Button 基本一致。
只需要传入一个title
和我们此前声明的 YCUINavigationBarConfig
即可,同时提供了可选的单击回调onBackClicked
和 onRightClicked
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Builder navigationBar() { YCUINavigationBar({ config: this.navigationConfig, onBackClicked: () => { console.debug('点击了返回') }, onRightClicked: () => { console.debug('点击了右侧按钮') } }) .width('100%') .height('100vp') .position({x: 0, y: 0}) .backgroundColor(Color.White) }
|
API
配置文件 (YCUINavigationBarConfig)
配置参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| title: string = ''
backType: YCUINavigationBarBackType = YCUINavigationBarBackType.GREY_BACK
underlineVisibility: Visibility = Visibility.Hidden
jumpButtonVisibility: Visibility = Visibility.Hidden
shareButtonVisibility: Visibility = Visibility.Hidden
customerButtonVisibility: Visibility = Visibility.Hidden
export enum YCUINavigationBarBackType { GREY_BACK = 0, LIGHT_BACK = 1, CLOSE_BACK = 2 }
|
导航栏(YCUINavigationBar)
点击回调
1 2 3 4
| public onBackClicked?: () => void
public onRightClicked?: () => void
|
弹窗 - YCUIAlert
本地引入依赖
在使用方的 oh-package.json5
文件中添加如下代码依赖
1 2 3
| "dependencies": { "@ohos/uikit": "file:../uikit" }
|
Import 导入
导入所需的库内容,在使用的 .ets
文件内添加如下代码内容
1 2 3 4
| import { YCUIAlert, YCUIAlertConfig } from '@ohos/uikit'
|
基础使用代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| @Entry @Component struct UIKitPage { alertConfig: YCUIAlertConfig = new YCUIAlertConfig()
aboutToAppear(): void { this.alertConfig.navigationBarTitle = '支付结果确认' this.alertConfig.useNavigationShading = true this.alertConfig.size = { width: 350, height: 212 } this.alertConfig.style = YCUIAlertStyle.ALERT this.alertConfig.defaultStyle.textContent = '你指尖跃动的电光,是我永恒不变的信仰,唯我超电磁炮永世长存!' this.alertConfig.defaultStyle.confirmButtonTitle = '电磁炮发射' this.alertConfig.defaultStyle.confirmButtonTitle = '取消发射' }
@Builder navigationBar() { YCUINavigationBar({ config: this.navigationConfig, onBackClicked: () => { console.debug('点击了返回') }, onRightClicked: () => { console.debug('点击了右侧按钮') } }) .width('100%') .height('100vp') .position({x: 0, y: 0}) .backgroundColor(Color.White) }
@Builder button() { YCUIButton({ title: this.buttonTitle, config: this.buttonConfig, onTapClicked: () => { YCUIAlert.setConfig(this.alertConfig, () => { console.debug('弹窗已消失') }) YCUIAlert.setBlankContentArea(() => {this.alertContentView()}) YCUIAlert.show() } }) .offset({x: 0, y: -200}) .height(45) .margin(120) }
@Builder alertContentView() { Stack(){ Button('点击') .width(30) .height(30) .onClick(() => { YCUIAlert.dismiss() }) } .backgroundColor(Color.Red) .margin({top: 100}) .width(50) .height(50) .borderRadius(25) }
build() { Column() { Stack() { this.button() } .alignContent(Alignment.Center) } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }
|
运行效果

代码解释
首先我们需要声明一个配置文件 YCUIAlertConfig
,配置文件的内容决定了 YCUIAlert
的展示样式。注意:弹窗属于一次性样式,不支持配置文件的动态更新!
1 2
| alertConfig: YCUIAlertConfig = new YCUIAlertConfig()
|
其次,我们需要在页面声明周期开始时,也就是 aboutToAppear
阶段对配置内容进行初始化,下面的示例我们只修改了navigationBarTitle
、useNavigationShading
、size
、style
四项配置,其余均采用 UI 组件设计规范中默认的样式,如果需要使用默认样式,请设置defaultStyle
。
1 2 3 4 5 6 7 8 9 10 11 12
| this.alertConfig.navigationBarTitle = '支付结果确认' this.alertConfig.useNavigationShading = true this.alertConfig.size = { width: 350, height: 212 } this.alertConfig.style = YCUIAlertStyle.ALERT this.alertConfig.defaultStyle.textContent = '你指尖跃动的电光,是我永恒不变的信仰,唯我超电磁炮永世长存!' this.alertConfig.defaultStyle.confirmButtonTitle = '电磁炮发射' this.alertConfig.defaultStyle.confirmButtonTitle = '取消发射'
|
最后,我们在 build
中构建我们的 YCUIAlet
,用法非常简单。
- 只需要将弹窗的配置文件传入即可,
setConfig
的第一个参数为配置文件,第二个参数为弹窗消失时的回调,在开启蒙版点击的状态下,点击右上角关闭按钮和点击蒙版均会触发此回调,换句话说,只要弹窗消失回调就会触发 。
- 需要给弹窗空白区域传入一个 @Builder 修饰好的视图,否则弹窗空白区域将没有内容。
- 调用
show()
弹窗展示,调用dismiss
弹窗消失。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| YCUIAlert.setConfig(this.alertConfig, () => { console.debug('弹窗已消失') })
YCUIAlert.setBlankContentArea(() => {this.alertContentView()})
YCUIAlert.show()
@Builder alertContentView() { ... }
|
API
配置文件 (YCUIAlertConfig)
配置参数
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| style: YCUIAlertStyle = YCUIAlertStyle.ALERT
boardRadius: Length | BorderRadiuses = {topLeft: 12, topRight: 12}
navigationBarType: YCUIAlertNavigationBarType = YCUIAlertNavigationBarType.NORMAL
navigationBarTitle: string = ''
size: Size = { width: 0, height: 0 }
frame: Rect = Rect.Zero()
maskColor: ResourceColor = 'rgba(0,0,0,0.7)'
useNavigationShading: boolean = true
useCustomNavigation: boolean = false
enableClickMaskAreaCloseAlertView: boolean = false
showInSubWindow: boolean = false
defaultStyle: YCUIAlertDefaultStyle = new YCUIAlertDefaultStyle()
|
YCUIAlertDefaultStyle
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| sheetTitle: string = ''
sheetTipsTitle: string = ''
textContent: string = ''
textFontSize: number = 20
buttonLayoutDirection: YCUIAlertDefaultStyleButtonLayoutDirection = YCUIAlertDefaultStyleButtonLayoutDirection.HORIZONTAL
cancelButtonTitle: string = '取消'
confirmButtonTitle: string = '确认'
cancelClicked: () => void = () => {}
confirmClicked: () => void = () => {}
|
无数据视图 - YCUINoDataView
本地引入依赖
在使用方的 oh-package.json5
文件中添加如下代码依赖
1 2 3
| "dependencies": { "@ohos/uikit": "file:../uikit" }
|
Import 导入
导入所需的库内容,在使用的 .ets
文件内添加如下代码内容
1 2 3
| import { YCUINoDataView } from '@ohos/uikit'
|
基础使用代码示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| @Entry @Component struct UIKitPage { @State noDataTips: string = '没有下载的学案'
@Builder noDataView() { YCUINoDataView({tips: this.noDataTips}) .width('100%') .height('100%') }
build() { Column() { this.noDataView() } .width('100%') .height('100%') .justifyContent(FlexAlign.Center) } }
|
运行效果

代码解释
只需要传入对应文案即可,如果需要根据业务需求动态切换展示文案,标记为 @State 即可。
1 2
| @State noDataTips: string = '没有下载的学案'
|
注意:无数据视图当前只支持配置文案,不支持图片替换