-
Label 줄바꿈 속성ios 2020. 5. 11. 23:24
서브 프로젝트를 진행하던 도중, Label에 들어간 문자열에 줄 바꿈에 필요했습니다.
줄바꿈을 하기위해 \n(New line) 을 사용하여도 줄 바꿈이 되지 않는 점을 발견
label의 constraint가 문제인줄 알고 heigt와 width를 확장을 해도 돌아오는건
원하는 결과
"It will help you
If you register your height and weigh"
현실
"It will help you "
https://developer.apple.com/documentation/uikit/uilabel/1620539-numberoflines
numberOfLines - UILabel | Apple Developer Documentation
Instance Property numberOfLines The maximum number of lines to use for rendering text. Declarationvar numberOfLines: Int { get set } DiscussionThis property controls the maximum number of lines to use in order to fit the label’s text into its bounding re
developer.apple.com
문서를 확인해보니 ,
This property controls the maximum number of lines to use in order to fit the label’s text into its bounding rectangle.
-> numberOfLines의 프로퍼티는 label의 텍스트가 알맞는 사각형안에 맞추어 들어가도록 최대치 라인 수를 지정한다.
The default value for this property is 1.
-> 기본값은 1 ( 그래서 아무리 new line을 적용해도, 적용되지 않았던 것)
To remove any maximum limit, and use as many lines as needed, set the value of this property to 0.
-> 줄의 최대치 한계를 제거하기 위해 그리고 필요로하는 많은 라인들을 위해서는 property를 0 으로 지정해라.
If you constrain your text using this property, the label truncates any text that doesn’t fit within the maximum number of lines and inside the bounding rectangle.
-> 만약 사용자가 이 프로퍼티를 사용하여 제약을 둔다면, 그 label은 최대치 라인 범위 내에 맞지 않는 텍스트를 짜른다고 한다.
To specify which part of the text the label should truncate, set the lineBreakMode property.
-> 상세하게 특정 라벨의 부분을 잘라야 한다면, lineBreakMode 프로퍼티를 사용해라.
예를 들어 보겠습니다.
만약) number Of Line을 3으로 지정한다면, sizeToFit 메서드는 현재 폰트로 3개의 라인을 보여 줄 수 있게 , 충분한 크기로 리사이징 되다는 것 입니다.
밑에 코드는 제가 적용한 코드 입니다.
'ios' 카테고리의 다른 글
단위 테스트 (Given, When, Then) 활용 (0) 2020.06.23 UICollectionView: Using Flow Layout (0) 2020.06.21 [ios] Then (1) 2020.04.17 WKWebView (0) 2020.03.20 UINavigationController -1 (0) 2020.03.13