Questions tagged [nsattributedstringkey]

32 questions
39
votes
8 answers

Cannot convert value of type NSAttributedString.DocumentAttributeKey to .DocumentReadingOptionKey

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,…
LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
21
votes
3 answers

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

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 :…
Fawwad Ahmed
  • 234
  • 1
  • 4
  • 12
15
votes
2 answers

Swift NSAttributedStringKey not applying foreground color correctly

I am trying to create a meme generator app to better my understanding of Swift, Xdode, delegates, and UIKit. I am attempting to set the color of the meme text to white with a black stroke using NSAttributedStringKey. The black stroke is working, but…
Andrew Tuzson
  • 619
  • 8
  • 28
8
votes
3 answers

NSAttributedStringKey error with swift 4

After updating to Swift 4 I am getting an error on this code attributes["NSFont"] = font attributes["NSColor"] = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1) Cannot subscript a value of type '[NSAttributedStringKey : Any]' with an…
j.doe
  • 4,559
  • 6
  • 20
  • 31
5
votes
1 answer

Cannot convert value of type 'NSAttributedString.Key' to expected dictionary key type 'String' error(swift4.2)

Error in below two lines of code while upgrading from swift 3 to swift 4.2 let lineattribute : [String: Any] = [ NSForegroundColorAttributeName : UIColor(hexString: "#0f88b7ff")!, NSUnderlineStyleAttributeName :…
Vork
  • 746
  • 2
  • 12
  • 34
5
votes
1 answer

NSAttributedStringKey.foregroundColor not working

I'm using ZSWTappableLabel and ZSWTaggedString to show links inside a label. import ZSWTappableLabel import ZSWTaggedString The pod versions are: pod 'ZSWTappableLabel', '~> 2.0' pod 'ZSWTaggedString/Swift', '~> 4.0' The links used to appear…
Prabhu
  • 12,995
  • 33
  • 127
  • 210
3
votes
2 answers

UITextField attributedPlaceholder color and opacity in swift 4

I have custom textField which has @IBInspectable property placeHolderColor: UIColor and it works fine. I set it by: attributedPlaceholder = NSAttributedString(string: placeHolder, attributes:[NSAttributedStringKey.foregroundColor:…
emerog
  • 69
  • 3
  • 10
3
votes
1 answer

Cannot convert value of type 'NSAttributedString.DocumentAttributeKey' to expected dictionary key type 'NSAttributedString.DocumentReadingOptionKey'

I have just updated to Xcode 9 and converted my app from swift 3 to swift 4 and get this errors. how i can fix this? func displayText() { do { if url.pathExtension.lowercased() != "rtf" { let fileContent = try…
user8755398
3
votes
1 answer

Cannot subscript a value of type '[String : AnyObject]' with an index of type 'NSAttributedStringKey'

I am using below code in my project. After update to swift 4 I am getting errors. How can I fix it? Code: let returnString : NSAttributedString if styleList.count > 0 { var attrs = [String:AnyObject]() …
user8755398
2
votes
1 answer

How do I change the appearance of Markdown-styled text in an AttributedString?

WWDC 2021 introduced new AttributedString APIs in Foundation, including Markdown support. I'd like to change the appearance of .stronglyEmphasized text in an AttributedString created via markdown, to make the emphasised text's foreground colour red…
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97
2
votes
3 answers

Swift 4 Conversion error - Type 'NSAttributedStringKey' has no member 'foregroundColorNSAttributedStringKey'

I converted my code from Swift 3 to Swift 4 but getting this error: Type 'NSAttributedStringKey' has no member 'foregroundColorNSAttributedStringKey' My code is: let labelText = NSMutableAttributedString(string:…
KhanShaheb
  • 714
  • 2
  • 11
  • 26
2
votes
1 answer

Error setting 'foregroundColor' in macOS

In a macOS project using Swift 3.2, I'm trying to set the foreground color of a UITextView. let placeHolderTitleString: NSAttributedString = NSAttributedString(string: "Enter text here", attributes: [NSAttributedStringKey.foregroundColor :…
Cue
  • 2,952
  • 3
  • 33
  • 54
1
vote
1 answer

Trigger event when hovering over a particular word in NSTextView

I need to create a popover when a users hovers over a particular word in NSTextView e.g "The boy owns a dog" Once the user has the cursor over a dog (mouse up with nothing selected), a cocoa event needs to fire so i can perform an action, which is…
Jimmy
  • 1,433
  • 2
  • 14
  • 19
1
vote
1 answer

How to check two NSAttributedString.key of a NSAttributed string for equality?

I am implementing a set game where my cards are buttons which consist of NSAttributedString as attributed titles. To check whether three selected cards make a set or not I wanted to compare the attributes on each attributed string (which are…
Rhidita
  • 144
  • 11
1
vote
2 answers

How to make tappable NSAttributedString Move To Another ViewController Swift

I'm working on a simple app and add programatically NSAttributedString. I am really confused how to move present viewcontroller to another viewcontroller. This is not duplicate question because my question for how move to view controller and…
1
2 3