Swift 4 attributedString get typing attributes

前端 未结 3 1099
轻奢々
轻奢々 2021-01-05 01:52

I am trying to create AttributedString and add the attributes from

typingAttributes(from textView)

The problem is that

.typingAt

3条回答
  •  醉梦人生
    2021-01-05 02:30

    Even better solution I think. I created extension.

    public extension Dictionary {
        func toNSAttributedStringKeys() -> [NSAttributedStringKey: Any] {
            var atts = [NSAttributedStringKey: Any]()
    
            for key in keys {
                if let keyString = key as? String {
                    atts[NSAttributedStringKey(keyString)] = self[key]
                }
            }
    
            return atts
        }
    }
    

    https://gist.github.com/AltiAntonov/f0f86e7cd04c61118e13f753191b5d9e

提交回复
热议问题