【发布时间】:2014-05-02 06:42:49
【问题描述】:
我想写在我的 tableview 单元格 detailTextLabel 的同一行。
例如
Left string right string.
我正在这样做:
NSMutableAttributedString *descriptionAttribute = [[NSMutableAttributedString alloc] initWithString:descriptionString];
NSMutableAttributedString *dateAttribute = [[NSMutableAttributedString alloc] initWithString:finalDate];
NSMutableAttributedString *shareAttribute = [[NSMutableAttributedString alloc] initWithString:@"Share"];
NSMutableParagraphStyle *dateStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[dateStyle setAlignment:NSTextAlignmentLeft];
NSMutableParagraphStyle *shareStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[shareStyle setAlignment:NSTextAlignmentRight];
[dateAttribute addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 13)];
[dateAttribute addAttribute:NSParagraphStyleAttributeName value:dateStyle range:NSMakeRange(0, 13)];
[shareAttribute addAttribute:NSForegroundColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, 8)];
[shareAttribute addAttribute:NSParagraphStyleAttributeName value:shareStyle range:NSMakeRange(0, 5)];
[descriptionAttribute appendAttributedString:[dateAttribute mutableCopy]];
[descriptionAttribute appendAttributedString:[shareAttribute mutableCopy]];
myTableViewcell.detailTextLabel.attributedText = descriptionAttribute;
如果我在日期和共享属性字符串之间添加\n,结果很好。
但我想在同一行上有两个字符串..
一个想法?
谢谢
【问题讨论】:
-
你可以有两个具有相同属性和不同文本左右对齐的标签
-
好的,但是由于很多原因,我想把我的字符串写在detailTextLabel中
-
你是怎么添加的\n你的descriptionString和finaldate是什么
-
我在“share”字符串之前添加了
\n。描述字符串是没有特定样式的简单字符串。最终日期只是一个包含日期的 NSString。 -
我还是不明白这个问题。你想要这样的“描述 11/12/13 分享”吗
标签: ios uilabel detailtextlabel