8

I have an NSAttributedString, I need to insert some text in the middle of the text in my attributedString, how can i do that?

0

1 Answer 1

15
NSAttributedString *someAttrString = ...; // the original string you want to modify
NSAttributedString *someOtherAttrString = ...; // the text you want to insert
NSUInteger whereItGoes = ...; // where you want to insert the string

NSMutableAttributedString *mutableString = [someAttrString mutableCopy];
if (mutableString) {
    [mutableString insertAttributedString: someOtherAttrString atIndex: whereItGoes];
    // mutableString now contains the modified data; it's up to you
    // how it gets used in your app.

    [mutableString release];
}
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.