[英]How can I set a highlighted image on a table view cell?
我遵循了Apple AdvancedTableViewCells中的代碼,並使用單元格的背景圖像構建了表格視圖。 現在,我想對其進行更改,以使其代替藍色的突出顯示顏色,從而顯示圖像的較暗版本。 為此,我需要遵循哪些步驟? 我正在使用帶有自定義NIB的UITableViewCell
子類。 我的背景圖像實現為cell.backgroundView
。
到目前為止,我采取的步驟是:
selectionStyle
更改為“ None” UILabel
子視圖上的突出顯示顏色設置為淺色 setSelected: animated:
我想知道下一步。
您是否嘗試過替換setSelected: animated:
的圖像?
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if (selected) {
// replace image here
// or move a pointer from one image to another
}
}
我找到了selectedBackgroundView
屬性。 我正在使用這種方法,而不是setSelected: animated:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:@"TableBackground" ofType:@"png"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundImagePath];
self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
self.backgroundView.frame = self.bounds;
NSString *selectedBackgroundImagePath = [[NSBundle mainBundle] pathForResource:@"TableBackgroundDark" ofType:@"png"];
UIImage *selectedBackgroundImage = [UIImage imageWithContentsOfFile:selectedBackgroundImagePath];
self.selectedBackgroundView = [[[UIImageView alloc] initWithImage:selectedBackgroundImage] autorelease];
self.selectedBackgroundView.frame = self.bounds;
return self;
}
我不確定這是否正確,因為它引入了其他一些問題。 一件事是單元格selectionStyle
必須是UITableViewCellSelectionStyleNone
以外的其他東西,否則它不會顯示背景圖像。 取消選擇動畫也已停止工作。 我將針對這些問題提出一個新問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.