IOS Multiple right and left align on same line

前端 未结 3 731
南笙
南笙 2020-12-10 06:26

I want to write on the same line of my tableview cell detailTextLabel.

For example Left string right string.

I\'m doing this :

3条回答
  •  北海茫月
    2020-12-10 06:39

    It's possible to indirectly use NSTextTable which is unavailable on iOS.

    If you create html table like:

    Left string Right string

    And then convert it to an attributed string like that way:

    extension NSAttributedString {
      convenience init?(html: String) {
        guard let data = html.data(using: .utf8) else {
            return nil
        }
    
        try? self.init(data: data, options: [
            NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
            NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue
        ], documentAttributes: nil)
      }
    }
    

    You will get exactly what you need and if you check paragraph attributes in that attributed string - you will see NSTextTable there.

提交回复
热议问题