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

标签 iphone objective-c nsattributedstring

我有一个 NSAttributedString,我需要在我的 attributedString 中的文本中间插入一些文本,我该怎么做?

最佳答案

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

关于iphone - Objective-C - 在 NSAttributedString 中插入字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6644731/

相关文章:

ios - iOS/iPhone/iPad:确定名片上放置的对象的大小

iPhone - 按 CGRect 的 origin.x 对字典数组进行排序

ios - 子类化时出现 "duplicate symbols for architecture"错误

ios - 这个调试消息是什么意思?

ios - 如何正确设置 uicollectionviewcells?

iphone - 使用自定义 segue 时 UIActivityIndi​​catorView 卡住

iphone - 如何在 iOS 4(3.1.3 更新)上使用 MPMoviePlayerController

objective-c - 是否可以制作没有圆边的 UITextField?

ios - 带有 NSAttributedString 的 UILabel 忽略换行符

ios - 使用 Core Text 布置单个字形