Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Created March 3, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usagimaru/ad9626def34ecff88fdb2a7098ce8e72 to your computer and use it in GitHub Desktop.
Save usagimaru/ad9626def34ecff88fdb2a7098ce8e72 to your computer and use it in GitHub Desktop.
CTParagraphStyle
var minimumLineHeight: CGFloat = 0
var maximumLineHeight: CGFloat = 0
let paragraphSettings: [CTParagraphStyleSetting] = [
CTParagraphStyleSetting(spec: .minimumLineHeight, valueSize: MemoryLayout<CGFloat>.size, value: &minimumLineHeight),
CTParagraphStyleSetting(spec: .maximumLineHeight, valueSize: MemoryLayout<CGFloat>.size, value: &maximumLineHeight)
]
// sizeof(T) ... MemoryLayout<T>.size
let paragraphStyle = CTParagraphStyleCreate(paragraphSettings, paragraphSettings.count)
// Attributed String
let attributes: [NSAttributedStringKey : Any] = [
NSAttributedStringKey.init((kCTParagraphStyleAttributeName as String)) : paragraphStyle,
]
let attributedText = NSMutableAttributedString(string: "test", attributes: attributes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment