2012-04-13 5 views
1

私はUITableViewcellの必要な高さを計算するのにsizeWithFont:constrainedToSize:lineBreakMode:を使用しています。以下のコードは、iPhoneとiPadでうまく動作します。Xcode:sizeWithFont:constrainedToSize:lineBreakMode:システムテキストの色に関するiPadの問題?

IB(ストーリーボード)では、テキストカラーを「ダークグレーカラー」に設定しました(iPhoneとiPad用に別々のストーリーボードを使用していて、両方で色を設定しています)。 iPhoneは完璧に動作します。 iPadはダークグレーを使用していないのに対し、デフォルトのテキストカラー(ブラック)を使用しているように見えますが、変更できないようです。これはおそらく既知のバグですか、何か間違ったことをしましたか?

おそらく私のsizeWithFont:constrainedToSize:lineBreakMode:または他のどこかにテキストカラーをプログラムで追加する方法はありますか?

非常に高く評価されています。

if ([self.storyDescription description]) summary = [self.storyDescription description]; 

     if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPad) { 
      CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:15] 
         constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding 
          lineBreakMode:UILineBreakModeWordWrap]; 
      return s.height + 20; // Add padding 
     } else { 
      CGSize s = [summary sizeWithFont:[UIFont systemFontOfSize:18] 
          constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, MAXFLOAT) // - 40 For cell padding 
           lineBreakMode:UILineBreakModeWordWrap]; 
      return s.height + 40; // Add padding 
     } 

    } 

答えて

1

sizeWithFont:constrainedToSize:lineBreakMode:単にNSStringの大きさを算出します。 NSStringには色の概念がないため、この方法でも色は気になりません。

UILabelインスペクタのXcodeストーリーボードエディタで色を設定する必要があります。または、データソース/デリゲートメソッドUITableViewではUITableViewCelltextLabeldetailTextLabelを設定することができます。

+0

私はXcode Storyboardで色を設定しましたが、もう一度iPhoneでのみ動作します。 IPadは私がストーリーボードで何を設定しても気にしないようです。私はプログラムでそれをやった: 'if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad){ cell.textLabel.font = [UIFont systemFontOfSize:16.0]; cell.textLabel.textColor = [UIColor darkGrayColor]; cell.detailTextLabel.textColor = [UIColor darkGrayColor]; cell.textLabel.shadowColor = [UIColor lightTextColor]; cell.textLabel.shadowOffset = CGSizeMake(1,1); } ' – user1297842

関連する問題