1

I am trying to create a attributed string and add it to a textfield along with a non attributed string. When I try to create the attributed string I get the exception :

Extra Argument String in Call.

Should be self explanatory but can't see it, code is

let theString : NSString = "Correct Answers: "
        let labelFont = UIFont(name: "HelveticaNeue-Bold", size: 18)
        let attributes : Dictionary = [NSFontAttributeName : labelFont]

//Exception thrown here
var attrString = NSAttributedString(string: "Foo", attributes:attributes);

textfield.text = attrString + "blah blah blah";

Thanks in advance.

1 Answer 1

1

You should unwrap your "labelFont" for the attributes.

Also, you can't do

attrString + "blah blah blah"

because you can't directly add a String and a NSAttributedString.

You can use a NSMutableAttributedString:

let labelFont = UIFont(name: "HelveticaNeue-Bold", size: 18)
let attributes = [NSFontAttributeName : labelFont!]
var attrString = NSMutableAttributedString(string: "Foo", attributes: attributes)
let newString = NSAttributedString(string: " blah blah blah")
attrString.appendAttributedString(newString)
println(attrString.description)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.