Text alignment & auto wrap(텍스트 정렬 및 자동 줄 바꿈)

Text alignment & auto wrap
(텍스트 정렬 및 자동 줄 바꿈)

With alignment mode, with horizontal and vertical attributes, can let text be displayed in the center of the text area. Here we can get a first look at the parameters from API, through the example code as introduce. API parameters for text styles are in laya.display.text :
(정렬 모드에서는 가로 및 세로 속성을 사용하여 텍스트를 텍스트 영역의 가운데에 표시 할 수 있습니다. 여기에서 우리는 API의 매개 변수를 처음부터 살펴볼 수 있습니다. 예제 코드는 소개입니다. 텍스트 스타일의 API 매개 변수는 laya.display.text에 있습니다.)
1
2
3
4
Set the font style in the code, define text content in text area, and then put it horizontally and vertically centered. Horizontal and vertical alignment settings of text will not work without setting up directly the text areas.
(코드에서 글꼴 스타일을 설정하고 텍스트 영역에서 텍스트 내용을 정의한 다음 가로 및 세로 가운데에 배치합니다. 텍스트 영역을 직접 설정하지 않으면 텍스트의 가로 및 세로 정렬 설정이 작동하지 않습니다.)
  1. //初始化引擎(엔진 초기화)
  2. Laya.init(1136,640);
  3. var txt = new Laya.Text();
  4. //设置文本内容(텍스트 콘텐츠 설정)
  5. txt.text = "hello_world";
  6. //设置文本区背景(텍스트 영역 배경 설정)
  7. txt.bgColor = "#c30c30";
  8. //设置文本的宽高(텍스트의 너비 설정)
  9. txt.width = 400;
  10. txt.height = 400;
  11. //设置文本水平居中(텍스트를 중앙에서 가로로 설정)
  12. txt.align = "center";
  13. //设置文本垂直居中(텍스트를 중앙에 세로로 설정)
  14. txt.valign = "middle";
  15. Laya.stage.addChild(txt);
5
In current code, according your need, please refer to the other alignment values of the API. Which one can be more suitable in your project.
(현재 코드에서는 필요에 따라 API의 다른 정렬 값을 참조하십시오. 프로젝트에서 어느 것이 더 적합 할 수 있습니다.)
Whether text contents dimension over the textarea one, it may not displayed in the stage content. To handle this case, you can use automatic line break to show your entire text.
(텍스트 내용의 크기가 텍스트 영역을 초과하는지 여부에 관계없이 스테이지 내용에 표시되지 않을 수 있습니다. 이 경우를 처리하기 위해 자동 줄 바꿈을 사용하여 전체 텍스트를 표시 할 수 있습니다.)
API implementation:
(API 구현 :)
6
In following code, we will use wordwrap to deal newline case.
(다음 코드에서는 단어 랩을 사용하여 줄 바꿈 문자를 처리합니다.)
Set the width and height of the text area, otherwise the text will wrap automatically according to the default text width. The code looks like as follows:
(텍스트 영역의 폭과 높이를 설정합니다. 그렇지 않으면 텍스트가 기본 텍스트 너비에 따라 자동으로 줄 바꿈됩니다. 코드는 다음과 같습니다.)
  1. //初始化引擎(初始化引擎)
  2. Laya.init(1136,640);
  3. var txt = new Laya.Text();
  4. //设置文本内容(设置文本内容)
  5. txt.text = "Layabox는 AS / JS / TS 개발자를위한 HTML5 개발 기술 솔루션을 제공하는 HTML5 엔진 기술 제공 업체이자 탁월한 게임 퍼블리셔입니다.";
  6. //设置文本区背景(텍스트 영역 배경 설정)
  7. txt.bgColor = "#c30c30";
  8. //设置文本的宽高(텍스트의 너비 설정)
  9. txt.width = 400;
  10. txt.height = 400;
  11. //设置文本水平居中(텍스트를 중앙에서 가로로 설정)
  12. txt.align = "center";
  13. //设置文本垂直居中(텍스트를 중앙에 세로로 설정)
  14. txt.valign = "middle";
  15. //设置自动换行(텍스트를 중앙에 세로로 설정)
  16. txt.wordWrap = true;
  17. Laya.stage.addChild(txt);
7
Here, you can see that our line set automaticly break in this text area.
(여기에서 우리의 라인 집합이 이 텍스트 영역에서 자동으로 깨지는 것을 볼 수 있습니다.)

댓글 없음:

댓글 쓰기