转换阵列NSAttributedString [英] Convert array to NSAttributedString

查看:191
本文介绍了转换阵列NSAttributedString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的NSMutableArray NSAttributedString 组成的。

我试图将其转换为一个单一的 NSAttributedString 分离所有的 NSAttributedString 的一个字符。

I'm trying to convert it to a single NSAttributedString separating all the NSAttributedString's with a character.

此方法类似于一个数组来一个转换的NSString componentsJoinedByString:@,方法但遗憾的是这种方法不存在 NSAttributedString

This approach is similar to the conversion of an array to a NSString with the componentsJoinedByString:@"," method but unfortunately this method doesn't exist with the NSAttributedString.

我如何转换的阵列?谢谢。

How can I convert the array? Thanks.

推荐答案

我最好的老路上:

NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] init];
NSAttributedString *jointElement = [[NSAttributedString alloc] initWithString:@","]
for (int i = 0; i < [yourArray count] -1; i ++)
{
    [attrStr appendAttributedString:[yourArray objectAtIndex:i]];
    [attrStr appendAttributedString:jointElement];
}
[attrStr appendAttributedString:[yourArray lastObject]];

这篇关于转换阵列NSAttributedString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆