我想在表格单元格(UILabel类型)中对齐日期,如下所示:
Monday 03 May
Tuesday 04 May
Wednesday 05 May
我尝试使用Attributed Strings,如下所示:
CTTextTabRef tabArray[] = { CTTextTabCreate(0, 12, NULL) }; // try 12 and see how it goes
CFArrayRef tabStops = CFArrayCreate( kCFAllocatorDefault, (const void**) tabArray, 1, &kCFTypeArrayCallBacks );
CTParagraphStyleSetting altSettings[] =
{
{ kCTParagraphStyleSpecifierTabStops, sizeof(CFArrayRef), &tabStops },
};
CTParagraphStyleRef style = CTParagraphStyleCreate( altSettings, sizeof(altSettings) / sizeof(CTParagraphStyleSetting) );
NSDictionary *dictionaryForATab = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge NSObject *)style, (NSString *)kCTParagraphStyleAttributeName, nil];
NSString *dateString = [self stringFromDate:date]; // returns something like this--> @"Monday \t 03 May"
cell.textLabel.attributedText = [[NSAttributedString alloc] initWithString:dateString attributes:dictionaryForATab];
但我得到了
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType mutableCopyWithZone:]: unrecognized selector sent to instance 0x951b8e0'
错误。
关于如何修复它的任何想法(或其他做同样事情的方式)?
(显然在工作日使用Courier(或任何等宽字体)和空间填充, 不是一个有效的答案。我正在寻找更复杂的东西。)