简体   繁体   English

Objective C - 在 NSAttributedString 中插入字符串?

[英]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?我有一个NSAttributedString ,我需要在我的属性字符串的文本中间插入一些文本,我该怎么做?

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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM