【发布时间】:2012-08-25 19:50:07
【问题描述】:
我在单元格字幕中有格式问题。 我想在单元格的副标题中显示一个字符串和一个数字
字符串左对齐,数字右对齐
我是这样试的:
rangeAutor = [rangeAutor stringByPaddingToLength:40-[rangeAutor length] withString:@" " startingAtIndex:0];
NSString *subTitle = [NSString stringWithFormat:@"by %@ %1.2f km", rangeAutor, rangeDistance];
cell.detailTextLabel.text = subTitle;
你可以在这里看到结果吗 :-( format problem
您对我有解决方案的想法吗?
由于我只有 7 个声誉,我无法在 cmets 中写下我的答案 :-( 所以我试着在这里做:
static NSString *const kIdentifier = @"SelectRange";
static NSInteger const kDistanceLabelTag = 1;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
UILabel *distanceLabel;
if (cell) {
distanceLabel = (UILabel *)[cell.contentView viewWithTag:kDistanceLabelTag];
} else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kIdentifier];
CGRect cellBounds = cell.bounds;
static CGFloat const kLabelHeight = 20.0f;
distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, cellBounds.size.height - kLabelHeight, cellBounds.size.width, kLabelHeight)];
distanceLabel.tag = kDistanceLabelTag;
distanceLabel.font = cell.textLabel.font;
distanceLabel.textColor = cell.textLabel.textColor;
distanceLabel.textAlignment = UITextAlignmentRight;
distanceLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[cell.contentView addSubview:distanceLabel];
}
UIImage *icon = [UIImage imageNamed:iconName];;
cell.imageView.image = icon;
cell.textLabel.text = rangeName;
cell.detailTextLabel.text = [@"by " stringByAppendingString:rangeAutor];
distanceLabel.text = [NSString stringWithFormat:@"%1.2f km", rangeDistance];
NSLog(@"RangeDistance: %1.2f", rangeDistance);
return cell;
抢劫梅奥夫
我只改变了一些小东西 但现在我在单元格中看不到 rangeDistance :-( 日志输出正常
【问题讨论】:
标签: objective-c format subtitle