반응형
extension NSAttributedString {
func withLineSpacing(_ spacing: CGFloat) -> NSAttributedString {
let attributedString = NSMutableAttributedString(attributedString: self)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineBreakMode = .byTruncatingTail
paragraphStyle.lineSpacing = spacing
attributedString.addAttribute(.paragraphStyle,
value: paragraphStyle,
range: NSRange(location: 0, length: string.count))
return NSAttributedString(attributedString: attributedString)
}
}
let introduction = NSAttributedString(string: "1. 프린터의 블루투스를 켜주세요.\n2. 연결하려는 프린터를 선택해주세요.").withLineSpacing(4)
instructionLabel.attributedText = introduction
참고 : https://stackoverflow.com/questions/39158604/how-to-increase-line-spacing-in-uilabel-in-swift
728x90
반응형
'Swift iOS 앱 개발 > Swift' 카테고리의 다른 글
Swift 4 -> Swift 5 Migration + Swift 버전 확인하는 법? (0) | 2021.07.09 |
---|---|
[Swift iOS] Dependency Manager : CocoaPods / Carthage / Swift Package Manager (0) | 2021.07.09 |
[Swift iOS] url 이용하여 image 받아오기 (0) | 2021.06.24 |
[Swift iOS] swift codable null handling (0) | 2021.06.24 |
[Swift iOS] 검색기능구현 - 문자열 탐색 NSString.CompareOptions (0) | 2021.06.22 |