Last active
January 24, 2022 04:36
-
-
Save sk-chanch/011314237befd75f66168f05d732bf5b to your computer and use it in GitHub Desktop.
NSParagraphStyleExtension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSParagraphStyleEx.swift | |
// AppStarterKit | |
// | |
// Created by Chanchana Koedtho on 20/1/2565 BE. | |
// | |
import Foundation | |
import UIKit | |
extension NSParagraphStyle{ | |
static func set(with config:[ParagraphStyleSetting])->NSParagraphStyle{ | |
let ps = NSMutableParagraphStyle() | |
config.forEach{ | |
switch $0 { | |
case .lineSpacing(let value): | |
ps.lineSpacing = value | |
case .minimumLineHeight(let value): | |
ps.minimumLineHeight = value | |
case .maximumLineHeight(let value): | |
ps.maximumLineHeight = value | |
case .alignment(let value): | |
ps.alignment = value | |
case .lineBreakMode(let value): | |
ps.lineBreakMode = value | |
case .paragraphSpacing(let value): | |
ps.paragraphSpacing = value | |
case .firstLineHeadIndent(let value): | |
ps.firstLineHeadIndent = value | |
case .headIndent(let value): | |
ps.headIndent = value | |
case .tailIndent(let value): | |
ps.tailIndent = value | |
case .paragraphSpacingBefore(let value): | |
ps.paragraphSpacingBefore = value | |
case .hyphenationFactor(let value): | |
ps.hyphenationFactor = value | |
} | |
} | |
return ps | |
} | |
} | |
enum ParagraphStyleSetting{ | |
case lineSpacing(_:CGFloat) | |
case minimumLineHeight(_:CGFloat) | |
case maximumLineHeight(_:CGFloat) | |
case alignment(_:NSTextAlignment) | |
case lineBreakMode(_:NSLineBreakMode) | |
case paragraphSpacing(_:CGFloat) | |
case firstLineHeadIndent(_:CGFloat) | |
case headIndent(_:CGFloat) | |
case tailIndent(_:CGFloat) | |
case paragraphSpacingBefore(_:CGFloat) | |
case hyphenationFactor(_:Float) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
let ps = NSParagraphStyle.set(with: [.lineSpacing(1), .minimumLineHeight(10), .alignment(.right)])