Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C - Inserting string in an NSAttributedString?

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

like image 211
aryaxt Avatar asked Jul 11 '11 00:07

aryaxt


1 Answers

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];
}
like image 181
Jonathan Grynspan Avatar answered Sep 21 '22 21:09

Jonathan Grynspan