UITableViewCellの選択色
-
05-07-2019 - |
質問
セルに組み込まれた textLabel
を使用せず、代わりに独自の描画を行うカスタム UITableViewCell
がある場合、どのように外観を変更できますか選択時に contentView
、デフォルトのテキストに対して自動的に行うように( selectedTextColor:
を設定してカスタマイズ可能)?
tableView:willSelectRowAtIndexPath:
を変更した場合、青色の選択背景がアップした後にのみ更新されますが、アニメーション中は更新されません。
解決
UITableViewCellをサブクラス化しないで、デフォルトの動作を使用してください。 サブクラス化せずにセルを完全にカスタマイズできます。
詳細については、この記事をご覧ください。
>他のヒント
このコードをtableview cellForRowAtIndexPathメソッドに追加し、UITableViewCell選択スタイルの予想される色を変更します。
//-------------------------------------------------------------------------
//background selected view
UIView *viwSelectedBackgroundView=[[UIView alloc]init];
viwSelectedBackgroundView.backgroundColor=[UIColor colorWithRed:124.0/255.0 green:202.0/255.0 blue:227.0/255.0 alpha:1.0];
cell.selectedBackgroundView=viwSelectedBackgroundView;
//-------------------------------------------------------------------------
UITableViewCellをサブクラス化した場合、以下をオーバーライドすることでセルの要素をカスタマイズできます。
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
if(highlighted) {
self.backgroundColor = [UIColor redColor];
} else {
self.backgroundColor = [UIColor clearColor];
}
[super setHighlighted:highlighted animated:animated];
}
所属していません StackOverflow