我一直在尝试一段时间,现在似乎找不到解决方案。我在我的tableview中使用了UITableViewCellStyleDefault
cellstyle,并且在文本变得太长时,我试图调整字体的大小。在uitableviewcellstyledefault调整标题
细胞创作
static NSString *CellIdentifier = @"thisMonthCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
[cell.textLabel setTextColor:[UIColor darkGrayColor]];
[cell.textLabel setAdjustsFontSizeToFitWidth:YES];
[cell.textLabel setMinimumFontSize:14];
UILabel *valueLabel = [[UILabel alloc]initWithFrame:CGRectMake(190, 10, 100, 20)];
[valueLabel setBackgroundColor:[UIColor clearColor]];
valueLabel.tag = 1001;
[valueLabel setTextAlignment:UITextAlignmentRight];
[cell addSubview:valueLabel];
}
Expense *expense = [[self.dataHandler monthExpenses]objectAtIndex:indexPath.row];
UILabel *value = (UILabel*)[cell viewWithTag:1001];
[cell.textLabel setText:[expense name]];
if ([[expense value]doubleValue] > 0) {
[value setText:[NSString stringWithFormat:@"+%.2f",[[expense value]doubleValue]]];
[value setTextColor:[self greenColor]];
}
else{
[value setText:[NSString stringWithFormat:@"%.2f",[[expense value]doubleValue]]];
[value setTextColor:[self redColor]];
}
return cell;
但不知何故textLabel
不会调整,如果文本太长。
这里是一个屏幕截图,展示问题:
什么想法?
更新我设法实现我的目标,通过删除standardlabel并添加一个自定义的,..奇怪的是,它不会与标准的工作。
我加入他们 - 但它并没有改变任何东西(它的'textLabel'太长而不值得) – 2012-04-20 08:38:01
valueLabel.numberOfLines = INT_MAX ..你可以用这个语句检查一次。 – rishi 2012-04-20 08:52:29
那里没有变化,.. sry – 2012-04-20 08:58:36