mirror of
https://github.com/metabolist/metatext.git
synced 2024-12-24 14:30:28 +00:00
25 lines
857 B
Swift
25 lines
857 B
Swift
|
// Copyright © 2020 Metabolist. All rights reserved.
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
extension String {
|
||
|
func countEmphasizedAttributedString(count: Int, highlighted: Bool = false) -> NSAttributedString {
|
||
|
let countRange = (self as NSString).range(of: String.localizedStringWithFormat("%ld", count))
|
||
|
|
||
|
let attributed = NSMutableAttributedString(
|
||
|
string: self,
|
||
|
attributes: [
|
||
|
.font: UIFont.preferredFont(forTextStyle: .body),
|
||
|
.foregroundColor: highlighted ? UIColor.tertiaryLabel : UIColor.secondaryLabel
|
||
|
])
|
||
|
attributed.addAttributes(
|
||
|
[
|
||
|
.font: UIFont.preferredFont(forTextStyle: .headline),
|
||
|
.foregroundColor: highlighted ? UIColor.secondaryLabel : UIColor.label
|
||
|
],
|
||
|
range: countRange)
|
||
|
|
||
|
return attributed
|
||
|
}
|
||
|
}
|