텍스트 킷으로 고정 된 행 높이의 속성 문자열을 그릴 때 문자는 항상 선 조각의 맨 아래에 정렬됩니다. 크기가 다른 문자를 한 줄에 사용하는 것이 좋지만 여러 줄이있는 텍스트의 흐름이 손상됩니다. 기준선은 각 선에 대해 가장 큰 디 센더에 의해 결정됩니다.큰 줄 높이의 문자로 기준선을 텍스트 키트로 맞 춥니 다
이 정확한 문제를 조금 더 자세히 설명하고 해결책이 무엇인지 보여주는 Sketch의 사람들로부터 article이 발견되었지만 분명히 설명하지 못했습니다. 이 문제를 해결했습니다.
큰 라인 높이 두 줄을 보여주는이 결과는 이상적인 거리가 멀다 :
코드 내가 사용 :
이
은 기본적으로 내가 원하는 것입니다let smallFont = UIFont.systemFont(ofSize: 15)
let bigFont = UIFont.systemFont(ofSize: 25)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.minimumLineHeight = 22
paragraphStyle.maximumLineHeight = 22
var attributes = [
NSFontAttributeName: smallFont,
NSParagraphStyleAttributeName: paragraphStyle
]
let textStorage = NSTextStorage()
let textContainer = NSTextContainer(size: CGSize(width: 250, height: 500))
let layoutManager = NSLayoutManager()
textStorage.append(NSAttributedString(string: "It is a long established fact that a reader will be ", attributes:attributes))
attributes[NSFontAttributeName] = bigFont
textStorage.append(NSAttributedString(string: "distracted", attributes:attributes))
attributes[NSFontAttributeName] = smallFont
textStorage.append(NSAttributedString(string: " by the readable content of a page when looking at its layout.", attributes:attributes))
layoutManager.addTextContainer(textContainer)
textStorage.addLayoutManager(layoutManager)
let textView = UITextView(frame: self.view.bounds, textContainer:textContainer)
view.addSubview(textView)
세부 정보를 게시 할 수 있습니까? 나는 당신이 이것을 어떻게하는지 궁금합니다. – ctietze
간단한 구현으로 업데이트되었습니다. – Pim