宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
OKProject/Extension/AttributedStringbuilder.swift
@@ -16,18 +16,22 @@
        return AttributedStringbuilder()
    }
    
    @discardableResult
    func add(string: String,withFont: UIFont,withColor: UIColor,lineSpace: CGFloat) -> AttributedStringbuilder {
        let style = NSMutableParagraphStyle()
        style.lineSpacing = lineSpace
        mutableAttributedString.append(NSAttributedString(string: string, attributes: [NSAttributedString.Key.foregroundColor: withColor,NSAttributedString.Key.font: withFont, NSAttributedString.Key.paragraphStyle: style]))
        return self
    }
    @discardableResult
    func add(string: String,withFont: UIFont,withColor: UIColor,backColor: UIColor) -> AttributedStringbuilder {
        let style = NSMutableParagraphStyle()
        mutableAttributedString.append(NSAttributedString(string: string, attributes: [NSAttributedString.Key.foregroundColor: withColor,NSAttributedString.Key.font: withFont,NSAttributedString.Key.backgroundColor: backColor, NSAttributedString.Key.paragraphStyle: style]))
        return self
    }
    
    @discardableResult
    func add(string: String,withFont: UIFont,withColor: UIColor,indent: CGFloat) -> AttributedStringbuilder {
        let style = NSMutableParagraphStyle()
        style.firstLineHeadIndent = indent
@@ -35,6 +39,7 @@
        return self
    }
    
    @discardableResult
    func add(string: String,withFont: UIFont,withColor: UIColor,indent: CGFloat,lineSpace: CGFloat) -> AttributedStringbuilder {
        let style = NSMutableParagraphStyle()
        style.firstLineHeadIndent = indent
@@ -43,6 +48,7 @@
        return self
    }
    
    @discardableResult
    func underLine() -> AttributedStringbuilder {
        let range1 = NSRange(location: 0, length: mutableAttributedString.string.count)
        let number = NSNumber(value:NSUnderlineStyle.single.rawValue)
@@ -50,23 +56,25 @@
        return self
    }
    
    @discardableResult
    func add(string: String,withFont: UIFont,withColor: UIColor) -> AttributedStringbuilder {
        mutableAttributedString.append(NSAttributedString(string: string, attributes: [NSAttributedString.Key.foregroundColor: withColor,NSAttributedString.Key.font: withFont]))
        return self
    }
    
    @discardableResult
    func add(string: String,withSize: CGFloat,withColor: UIColor) -> AttributedStringbuilder {
        mutableAttributedString.append(NSAttributedString(string: string, attributes: [NSAttributedString.Key.foregroundColor: withColor,NSAttributedString.Key.font: UIFont.systemFont(ofSize: withSize)]))
        return self
    }
    
    @discardableResult
    func attach(attachment: NSTextAttachment) -> AttributedStringbuilder {
        mutableAttributedString.append(NSAttributedString(attachment: attachment))
        return self
    }
    
    @discardableResult
    func attach(image: UIImage) -> AttributedStringbuilder {
        let attachment = NSTextAttachment()
        attachment.image = image