鴻蒙2:常用組件開(kāi)發(fā)

一.基本介紹

1.組件

ArkUI(方舟開(kāi)發(fā)框架)是一套 構(gòu)建 鴻蒙應(yīng)用 界面 的框架。 構(gòu)建頁(yè)面的最小單位就是 "組件"。

  • 容器組件:Column、Row
  • 基礎(chǔ)組件:Text

容器組件() { // 內(nèi)容
}

基礎(chǔ)組件(參數(shù))
@Entry
@Component
struct Index {
  @State message: string = '';
  build() {
    Column(){
      Text("容器")
    }
  }
}
2.屬性

屬性方法怎么寫(xiě)?

組件() {} .屬性方法1(參數(shù)) .屬性方法2(參數(shù)) .屬性方法3(參數(shù)) ......
image.png
二.文字組件
  Text("設(shè)備介紹")
        .fontColor("#8fbce7")
        .fontSize(20)
        .textOverflow({ overflow: TextOverflow.Ellipsis })//需要配合maxLines使用
        .maxLines(2)
        .width(10)
        .lineHeight(30)

三.圖片組件
  • Image(圖片數(shù)據(jù)源) 支持 網(wǎng)絡(luò)圖片資源 和 本地圖片資源
  • 圖片位置:main/resources/base/media/xx.png
 Image('https://www.itheima.com/images/logo.png').width(100)
 Image($r("app.media.app_icon_big")).width(50)

四.輸入框組件
  • InputType.Normal:基本輸入模式,無(wú)特殊限制
  • InputType.Password:密碼輸入模式
  TextInput({ placeholder: "請(qǐng)輸入文本" })
        .type(InputType.Normal)
五.按鈕組件
 Button("登錄")
六.Swiper 輪播組件
image.png
Swiper() {
        Image($r("app.media.layered_image"))
        Image($r("app.media.icon_tip"))
        Image($r("app.media.ic_back"))
        Image($r("app.media.foreground"))
      }
      .width("100%")
      .height(200)
      .indicator(
        Indicator.dot()// 小圓點(diǎn)
          .itemWidth(20)// 默認(rèn)的寬
          .itemHeight(20)// 默認(rèn)的高
          .color(Color.Black)// 默認(rèn)的顏色
          .selectedItemWidth(30)// 選中的寬
          .selectedItemHeight(30)// 選中的高
          .selectedColor(Color.White) // 選中的顏色
      )
      .autoPlay(true)
      .loop(true)
      .interval(3000)
      .vertical(false)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容