2011-01-17 9 views

答えて

8

(サブクラスのUITableViewCellなし)UITableViewCellのカスタムサブクラスを作成し、これを行うに-layoutSubviewsメソッドを実装:あなたはサブクラス化せずにそれをやってみたかった場合

- (void) layoutSubviews { 
    [super layoutSubviews]; 
    //my custom repositioning here 
} 

を、あなたは法のスウィズリングを経由してそれを行うことができますが、全体的に、それはBad Idea™です。

+0

サブクラス化しないとできませんか? – NSExplorer

+0

番号。 (フィラーはすべて途中で) –

+1

@iPhone開発者 - はい、サブクラス化せずに可能ですが、実行時にダイビングし、メソッドやものを手動で切り替える必要があります。完全に実現可能で、それほど難しいことではありませんが、実装がはるかに壊れやすくなります。それだけではなく、あなたのアプリのすべての* UITableViewCellに影響を与えます。 –

2

これはとても似NSAttributedStringとattributedTextプロパティを使用してサブクラス化せずに行うことができます。

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyReuseIdentifier"]; 

NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"Some Text"]; 
cell.textLabel.attributedText = text; 

NSMutableParagraphStyle *subtitleParagraphStyle = [NSMutableParagraphStyle new]; 
subtitleParagraphStyle.minimumLineHeight = 20; 

NSMutableAttributedString *subText = [[[NSAttributedString alloc] initWithString:@"Some Subtitle Text"] mutableCopy]; 
[subText addAttribute:NSParagraphStyleAttributeName value:subtitleParagraphStyle range:NSMakeRange(0, subText.length)]; 

cell.detailTextLabel.attributedText = subText; 

あなたがやっていることは、通常よりも大きくなるように字幕の行の高さを強制されます。テキストとサブテキストの行の高さで遊んで、あなたが望むものを達成するのに役立ちます。 iOS 7以降と互換性があります。

数年が経過していますが、うまくいけば誰かがそれが有用だと思っています。

関連する問題