2011-08-29 42 views
10

我已經創建了一個UITableView並自定義TableCell,通常按照本教程進行;UITableView - 突出顯示所選單元格[iOS]

http://www.theappcodeblog.com/?p=353

我把它定製,以我的需求和它看起來棒極了。但是,當我選擇一行時,通過將整個事物更改爲藍色來突出顯示該行。這個亮點覆蓋了整個單元格並覆蓋了內容,實際上製作了一個看起來很討厭的大藍盒子。如果選擇灰我都試過的

顯然備用突出顯示選項,同樣的行爲發生,但以灰色醜陋箱子。 '無'是一分鐘的理想選擇,但不會爲用戶提供良好的體驗,因爲我想說明他們選擇了該行。

任何人都可以提出一種方法來顯示該行是highligted,但仍然顯示下面的文本?半透明?

感謝

回答

11

也許是因爲你的代碼示例設置:

artistLabel.highlightedTextColor = [UIColor clearColor];

這會導致artistLabel的文字顏色在突出顯示時變爲透明。

原因,你可以將自己的顏色設爲您的標籤highlightedTextColor屬性,例如:

[UIColor whiteColor]

+0

我什麼絕對的白癡,謝謝。簡單的答案,完美的工作。謝謝 –

+1

不客氣。如果你認爲這個答案很有用,那麼投票並選擇它作爲正確的答案將非常感激。 – xuzhe

+0

我總是這樣做。我有100%提出非常問題,我問。再次感謝。 –

4

u可以使用烏爾自己的自定義視圖選擇

這裏我有綠色視圖像這樣你可以改變任何你想要的定製。

if (cell == nil) { 

    cell = [[[UITableViewCell alloc] initWithFrame: CGRectZero 
            reuseIdentifier: CellIdentifier] autorelease]; 


    UIView *selectionView = [[UIView alloc]initWithFrame:cell.bounds]; 

    [selectionView setBackgroundColor:[UIColor greenColor]]; 

    cell.selectedBackgroundView = selectionView; 


    [selectionView release]; 

} 
8

的UITableView單元格中所選顏色

享受...

// Image 
UIImage *selectionBackground = [UIImage imageNamed:@"g7.png"]; 
UIImageView *bgview=[[UIImageView alloc] initWithImage:selectionBackground]; 
cell.selectedBackgroundView=bgview; 
[bgview release]; 

// Color 
UIView *bgColorView = [[UIView alloc] init]; 
[bgColorView setBackgroundColor:[UIColor brownColor]]; 
[cell setSelectedBackgroundView:bgColorView]; 
[bgColorView release]; 
+0

很酷。顏色在iOS 7中可用。 – Tom

+0

我也建議調用[cell setSelectionStyle:UITableViewCellSelectionStyleNone],它在選中時防止單元格從其周界上的白色矩形。 –

相關問題