10 min read

问题描述 投票:0回答:2
I'd like to apply styles to everything after and including the pipe, so

I have tried the below but it has only styles the pipe itself.

I have some text: New Content - Published Today| 10 min read

  func makeAttributedText(using baseString: String?) -> NSMutableAttributedString? {
    guard let baseString = baseString else { return nil }
    let attributedString = NSMutableAttributedString(string: baseString, attributes: nil)
    let timeToReadRange = (attributedString.string as NSString).range(of: "|")
    attributedString.setAttributes([NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18)], range: timeToReadRange)
    return attributedString
  }
我有一些文字。
swift uilabel nsmutableattributedstring
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.