ios7 UITableViewCell selectionStyle不会回到蓝色

Xcode 5.0,iOS 7和更新现有的应用程序。 UITableView选中的行现在是灰色的,而不是蓝色的。

从我读过的,他们把默认的selectionStyle改成了灰色。 但是“蓝色”仍然是IB的一个选项,而UITableViewCellSelectionStyleBlue依然存在。 检查出新的HIG,看起来他们看起来不像他们删除蓝色和“设置”应用程序仍然使用蓝色单元格select。

我已经尝试在IB和代码中设置值,但没有运气。 我需要做什么来获得蓝色select风格的任何想法?

在iOS7中只有一个selectionStyle,改变你需要手动完成,如下所示:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { .... UIView *bgColorView = [[UIView alloc] init]; bgColorView.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0) alpha:1.0]; // perfect color suggested by @mohamadHafez bgColorView.layer.masksToBounds = YES; cell.selectedBackgroundView = bgColorView; .... return cell; } 

我知道这已经被回答,但我想要做的最后一件事是触摸我所有的cellForRowAtIndexPath方法。 所以,我在我的App Delegate中使用了一个外观代理。 我拿@ null的代码来设置所选的背景视图,并在applicationDidFinishLaunching:withOptions:方法中,我放置了这个代码。

 UIView *bgColorView = [[UIView alloc] init]; //the rest of null's code to make the view [[UITableViewCell appearance] setSelectedBackgroundView:bgColorView]; 

然后,使白色文字喜光:

 [[UILabel appearanceWhenContainedIn:[UITableViewCell class], nil] setHighlightedTextColor:[UIColor whiteColor]]; 

这使我的应用程序发生了全球变化。 外观代理是在iOS5中引入的,Mattt 在他的NSHipster博客上有一篇关于如何使用它的文章 。

可能它可以帮助你。 我有我的自定义单元格,并使其select所需的颜色我已经覆盖setHighlighted和setSelected现在看起来像这样

 #define IOS_7 (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 ? YES : NO) - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; [self changeSelectionColorForSelectedORHiglightedState:selected]; // Configure the view for the selected state } - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { [super setHighlighted:highlighted animated:animated]; [self changeSelectionColorForSelectedORHiglightedState:highlighted]; } - (void)changeSelectionColorForSelectedORHiglightedState:(BOOL)state { if (IOS_7) { if (state) { self.contentView.backgroundColor = [UIColor blueColor]; } } } 

我知道我真的很晚参加派对,但我也会提供IOS10的工作。 不要触摸你的其他代码,但是添加:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.backgroundColor = [UIColor blueColor]; cell.textLabel.textColor = [UIColor whiteColor]; ... whatever else you do ... } -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(nonnull NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; cell.backgroundColor = [UIColor whiteColor]; cell.textLabel.textColor = [UIColor blackColor]; }