Swift 5 字符串插值-AttributedStrings

extension AttrString.StringInterpolation { func appendInterpolation(_ string: String, _ style: AttrString.Style) { let astr = NSAttributedString(string: string, attributes: style.attributes) self.attributedString.append(astr) }然后就完成了...extension AttrString.StringInterpolation { func appendInterpolation(_ string: String, _ style: AttrString.Style...) { var attrs: [NSAttributedString.Key: Any] = [:] style.forEach { attrs.merge($0.attributes, uniquingKeysWith: {$1}) } let astr = NSAttributedString(string: string, attributes: attrs) self.attributedString.append(astr) }}现在可以将多种样式混合起来了...extension AttrString.StringInterpolation { func appendInterpolation(wrap string: AttrString, _ style: AttrString.Style...) { var attrs: [NSAttributedString.Key: Any] = [:] style.forEach { attrs.merge($0.attributes, uniquingKeysWith: {$1}) } let mas = NSMutableAttributedString(attributedString: string.attributedString) let fullRange = NSRange(mas.string.startIndex..<。

扫描二维码分享话题