0

I have a question about change string size and font in swift. I write some strings in txt file and I printed out with my app.In this point these strings size and font very small so I want to increase. I already tried to make it attributed string but its not allow me to call write code in show at below:

    @objc func handleTxt(){
    let file = "\(UUID().uuidString).txt"

    let orderIdStr = self.orderId.joined(separator: "\n")
    let myAttribute = [ NSAttributedString.Key.font: UIFont(name: "Comfortaa-Bold", size: 21.0)! ]
    let myAttrString = NSAttributedString(string: orderIdStr, attributes: myAttribute)

    let contents = myAttrString

    let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    let fileURL = dir.appendingPathComponent(file)

    do{
        try contents.write(to: fileURL, atomically: false, encoding: .utf8)
    }
    catch{
        print("error: \(error)")
    }
}

How can I change font and size of these string?

  • Does this answer your question? [How can I save the attributed string (text) into file (swift, cocoa)?](https://stackoverflow.com/questions/33178895/how-can-i-save-the-attributed-string-text-into-file-swift-cocoa) – koen Dec 04 '19 at 16:53
  • @koen I have string and I need to change font and size of it but in this point attributed string can't solve my problem because write not working with it. – swifdev Dec 04 '19 at 16:57
  • That link shows how to save attributed string to a file. If that's not what you want to do, please clarify your question. – koen Dec 04 '19 at 17:03

0 Answers0