2016-03-03 85 views
0

我看到以下問題,但沒有解釋,雖然您可以簡單地將cell.SelectedStyle設置爲UITableViewCellSelectionStyleGrayUITableViewCellSelectionStyleNone,但不能將其設置爲UITableViewCellSelectionStyleBlue爲什麼不能設置cell.selectionStyle = UITableViewCellSelectionStyleBlue?

他們只是提供了一個黑客沒有解釋。我只是想知道爲什麼這樣我能更好地理解Objective-C的

UITableViewCellSelectionStyleBlue is not working

ios7 UITableViewCell selectionStyle won't go back to blue

Cannot change UITableView blue highlight color

+0

cell.selectionStyle = UITableViewCellSelectionStyleBlue應放在返回單元格之前; –

回答

5

你不會喜歡的答案即可。截至iOS 7,設置

cell.selectionStyle = UITableViewCellselectionStyleBlue; 

現在會給你灰色。蘋果在iOS 7中擺脫了它,所以現在selectionStyleBlue不再以藍色存在..它是灰色的。

下面是來自UITableViewCell類,參考了蘋果的文檔報價:

選擇時,電池有一個默認的背景色。

在iOS 7中,選擇顏色不再是藍色。改爲使用UITableViewCellSelectionStyleDefault。

適用於iOS 2.0及更高版本。

當然,我相信你已經找到了,你可以創建一個UIView並將其設置爲模擬藍色選擇的背景。

下面是這種做法的鏈接:UITableView cell blue highlight on selection

編輯:

只要是明確的。 UITableViewCellSelectionStyleBlue使選擇風格變爲灰色。

UITableViewCell沒有默認方法使選擇樣式變爲藍色。

爲了使選擇樣式不同於默認灰色,您必須像我提供的鏈接中創建自定義UIView。

+0

謝謝! 蘋果擺脫了它!?!我無法理解你在說什麼。我可以在'UITableView.h'中看到它:@property(nonatomic)UITableViewCellSelectionStyle selectionStyle; //默認是UITableViewCellSelectionStyle *藍色*。' ALSOOO:'的typedef NS_ENUM(NSInteger的,UITableViewCellSelectionStyle){ UITableViewCellSelectionStyleNone, UITableViewCellSelectionStyle *藍*, UITableViewCellSelectionStyleGray, UITableViewCellSelectionStyleDefault NS_ENUM_AVAILABLE_IOS(7_0)' – Honey

+0

看到我編輯的問題.. UITableViewCellSelectionStyleBlue實際上是灰色的。我知道這是令人困惑,但所有的UITableViewCellSelectionStyle屬性將會是灰色的...從現在開始就像UITableViewCellSelectionStyleBlue不存在! (bc灰色) –

+0

@ asma22蘋果公司在發佈iOS 7時重新設計了UI。他們停止使用藍色進行選擇(它們實際上在每個應用程序中使用不同的顏色),並且常量不再有意義,因此將它們重命名爲「default」更明智。 – Sulthan

相關問題