【发布时间】:2013-12-04 04:03:46
【问题描述】:
我正在尝试将部分文本对齐到部分标题的左侧,并将不同的文本对齐到同一标题的右侧。
在使用工具栏时,我使用了一个灵活的按钮来左右推动其他两个按钮,我想知道部分标题是否有类似的东西?
更多背景知识是,我的表格视图中有一个不同的部分,用于在不同的日子输入的每条信息。在部分标题的左侧,我想要输入的日期(11 月 20 日星期三),在右侧我想要多少天前(20 天前)。
这是我目前使用的代码:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return nil;
}
else {
// This gets the day the data was entered
NSDate * date = [_sectionDates objectAtIndex:(section-1)];
NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"EEE"];
NSString * dateDay = [formatter stringFromDate:date];
[formatter setDateFormat:@"MMM"];
NSString * dateMonth = [formatter stringFromDate:date];
NSDateComponents * components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:date];
NSInteger dateOfDay = [components day];
NSTimeInterval diff = [[NSDate date] timeIntervalSinceDate:date];
NSInteger days = diff / (60.0 * 60.0 * 24);
NSString * dateScript;
if (dateOfDay < 21 && dateOfDay > 4) {
dateScript = @"th";
}
else if (dateOfDay % 10 == 1) {
dateScript = @"st";
}
else if (dateOfDay % 10 == 2) {
dateScript = @"nd";
}
else if (dateOfDay % 10 == 3) {
dateScript = @"rd";
}
else {
dateScript = @"th";
}
NSString * header;
if (days < 2) {
header = [NSString stringWithFormat:@"%@ %i%@ %@ - %@", dateDay, dateOfDay, dateScript, dateMonth, days == 0 ? bToday : bYesterday];
}
else {
header = [NSString stringWithFormat:@"%@ %i%@ %@ - %i %@", dateDay, dateOfDay, dateScript, dateMonth, days, bDaysAgo];
}
return header;
}
}
目前输出如下:
|12 月 4 日星期三 - 今天________|
我希望它是这样的:
|12 月 4 日星期三_________今天|
【问题讨论】:
标签: ios objective-c uitableview sections