我想寫在我的tableview單元格detailTextLabel的同一行上。IOS在同一行上多個左右對齊
例如 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
,效果良好。
,但我想對同一線上的兩個字符串..
的想法?
感謝
你可以有兩個標籤具有相同的性質和不同textalignment左右 –
好了,但有很多原因,我想寫出我的琴絃在detailTextLabel – user3433920
你添加\ n是怎麼做的,什麼是你的descriptionString和finaldate –