5
我在我的應用中需要行間距調整的包裝標籤(多行標籤)。我如何使用Swift或Interface Builder設置此NSTextField的行間距?Swift中的NSTextField行間距
我在我的應用中需要行間距調整的包裝標籤(多行標籤)。我如何使用Swift或Interface Builder設置此NSTextField的行間距?Swift中的NSTextField行間距
您可以使用NSAttributedString
修改這個(SWIFT 4例):
let title:String = "Your text"
let textParagraph:NSMutableParagraphStyle = NSMutableParagraphStyle()
textParagraph.lineSpacing = 10.0 /*this sets the space BETWEEN lines to 10points */
textParagraph.maximumLineHeight = 12.0/*this sets the MAXIMUM height of the lines to 12points */
let attribs = [NSAttributedStringKey.paragraphStyle:textParagraph]
let attrString:NSAttributedString = NSAttributedString.init(string: title, attributes: attribs)
titleTextField.attributedStringValue = attrString