nsattributedstringkey

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

∥☆過路亽.° 提交于 2019-12-13 04:43:36
问题 Below is line of code for the above mentioned issue. This issue is occurred in Swift 4.1 . let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white] navigationController?.navigationBar.titleTextAttributes = textAttributes 回答1: I've fixed this problem by replacing the Key for Attributed String. Here is my updated Code is: let textAttributes = [NSForegroundColorAttributeName : UIColor.white] navigationController?.navigationBar.titleTextAttributes = textAttributes 来源: https:/

Cannot convert value of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?'

这一生的挚爱 提交于 2019-11-28 10:46:05
How to convert values of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?' ? open class func drawText(context: CGContext, text: String, point: CGPoint, align: NSTextAlignment, attributes: [String : AnyObject]?) { var point = point if align == .center { point.x -= text.size(withAttributes: attributes).width / 2.0 } else if align == .right { point.x -= text.size(withAttributes: attributes).width } NSUIGraphicsPushContext(context) (text as NSString).draw(at: point, withAttributes: attributes) NSUIGraphicsPopContext() } This is a new feature of Swift 4. All

Cannot convert value of type NSAttributedString.DocumentAttributeKey to .DocumentReadingOptionKey

冷暖自知 提交于 2019-11-28 08:54:10
I found this string extension somewhere on SO that allows me to turn html code into an attributed string: func html2AttributedString() -> NSAttributedString { return try! NSAttributedString(data: self.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) } It worked fine in Swift 3, but with Swift 4, Xcode complains: Cannot convert value of type 'NSAttributedString.DocumentAttributeKey' to expected dictionary key type 'NSAttributedString.DocumentReadingOptionKey' How do I fix this? You

Cannot convert value of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?'

拜拜、爱过 提交于 2019-11-27 03:48:38
问题 How to convert values of type '[String : AnyObject]?' to expected argument type '[NSAttributedStringKey : Any]?' ? open class func drawText(context: CGContext, text: String, point: CGPoint, align: NSTextAlignment, attributes: [String : AnyObject]?) { var point = point if align == .center { point.x -= text.size(withAttributes: attributes).width / 2.0 } else if align == .right { point.x -= text.size(withAttributes: attributes).width } NSUIGraphicsPushContext(context) (text as NSString).draw(at:

Cannot convert value of type NSAttributedString.DocumentAttributeKey to .DocumentReadingOptionKey

有些话、适合烂在心里 提交于 2019-11-26 16:31:22
问题 I found this string extension somewhere on SO that allows me to turn html code into an attributed string: func html2AttributedString() -> NSAttributedString { return try! NSAttributedString(data: self.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) } It worked fine in Swift 3, but with Swift 4, Xcode complains: Cannot convert value of type 'NSAttributedString.DocumentAttributeKey'