文字空行高度与字体高度不一致怎么办?

问题澄清

@Component 
export default struct AuthView { 
  //… 
  build() {} 
} 
// 如何增加reflectColor方法,类似Button的width和height方法 
// 如何增加reflectColor方法,类似Button的width和height方法 
AuthView().reflectColor(color);
阅读 257
1 个回答

解决措施

成员函数的访问始终是私有的,也就是说外部是不能调用自定义组件的自定义方法。

代码示例

const TAG: string = 'testTag' 
 
@Entry 
@Component 
struct ColorPage { 
  @State message: string = 'CopyPage'; 
  @State someColor: Color = Color.Red 
  @State countDownFrom: number = 0 
 
  build() { 
    Row() { 
      Column() { 
        // 自定义组件的引用 
        AuthView({ countDownFrom: this.countDownFrom, color: this.someColor }) 
        Button('修改组件属性') 
          .width(80) 
          .height(60) 
          .onClick(() => { 
            hilog.info(0x00000, TAG, '修改组件属性'); 
            this.someColor = Math.random() > 0.5 ? Color.Gray : Color.Pink 
            this.countDownFrom++ 
            hilog.info(0x00000, TAG, 'this.countDownFrom:' + this.countDownFrom); 
            hilog.info(0x00000, TAG, 'this.someColor:' + this.someColor); 
          }) 
          .margin({ 
            bottom: '5%' 
          }) 
          .fontColor(this.someColor) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
} 
 
//自定义组件 
@Reusable 
@Component 
export default struct AuthView { 
  @State message: string = 'AuthView-组件'; 
  @Prop countDownFrom: number = 0; 
  @Link color: Color; 
 
  //注意这个无法在组件外部调用 
  mOne() { 
    this.color = Color.Black 
  } 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .margin({ 
            bottom: '3%' 
          }) 
        Text(String(this.countDownFrom)) 
          .margin({ 
            bottom: '3%' 
          }) 
 
        Button('内部组件影响外部颜色') 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .margin({ 
            bottom: '3%' 
          }) 
          .onClick(() => { 
            this.mOne() 
          }) 
      } 
      .width('100%') 
      .backgroundColor(this.color ? this.color : Color.Orange) 
    }.margin({ 
      bottom: '5%' 
    }) 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进