我一直在嘗試一段時間,現在似乎找不到解決方案。我在我的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