반응형
iOS 15.5, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.
let loremText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.justified
let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.baselineOffset: NSNumber(floatLiteral: 0)]
let attributesString = NSAttributedString(string: loremText, attributes: attributes)
label.attributedText = attributesString
텍스트 양쪽 정렬을 사용할 때, NSTextAlignment.justified를 쓴다.
영어에서는 단어 단위로 양쪽 정렬이 잘 되지만, 한글은 한 글자 단위로 양쪽 정렬이 되어 큰 차이가 없다.
반응형
'iOS > 코드조각' 카테고리의 다른 글
[iOS, Swift] LocalNotification 실행하기 (0) | 2022.08.21 |
---|---|
[iOS, Swift] UILabel 밑줄긋기(Underline) (0) | 2022.08.20 |
[iOS, Swift] UILabel 그림자 효과 넣기 (0) | 2022.08.20 |
[iOS, Swift] UILabel TextColor 설정 (NSAttributedString) (0) | 2022.08.20 |
[iOS, Swift] UILabel Font 설정 (0) | 2022.08.20 |