Swift NSMutableAttributedString NSMutableParagraphStyle firstLineHeadIndent左间距问题

时间:2019-02-13 13:58:44

标签: ios swift nsmutableattributedstring

想添加NSMutableAttributedString NSMutableParagraphStylefirstLineHeadIndent的左边距,但没有运气,firstLineHeadIndentheadIndent无效

我的实现:

lazy var priseField: UILabel = {
     let label = UILabel()

     label.font = UIFont.boldSystemFont(ofSize: 15)
     label.textColor = .black
     let string = self.addMutableAttribute(string: "50")
     string.append(self.addAttribute(string: "lari"))
     label.attributedText = string
     return label
}()

func addMutableAttribute(string:String = "") -> NSMutableAttributedString {

    let attribute:[NSAttributedString.Key : Any] = [ NSAttributedString.Key.foregroundColor: UIColor.black,
                                                     NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15)]

    let attrString = NSMutableAttributedString(string: string, attributes: attribute)
    return attrString
}

func addAttribute(string:String = "") -> NSMutableAttributedString {

    let paragraphStyle = NSMutableParagraphStyle()

    paragraphStyle.firstLineHeadIndent = 3;
    paragraphStyle.headIndent = 3

    let attribute:[NSAttributedString.Key : Any] = [

        .foregroundColor: UIColor.darkGray,
        .paragraphStyle: paragraphStyle,
        .font: UIFont.boldSystemFont(ofSize: 12),
        .baselineOffset: 1
    ]

    let attrString = NSMutableAttributedString(string: string, attributes: attribute)
    return attrString
}

结果是:

enter image description here

我想增加50到拉里之间的距离

0 个答案:

没有答案