我想知道如何更改UITableViewCell
的蓝色突出显示/选择颜色,有什么想法吗?
发布于 2016-07-27 02:57:49
在Swift中,在cellForRowAtIndexPath
中使用它
let selectedView = UIView()
selectedView.backgroundColor = .white
cell.selectedBackgroundView = selectedView
如果希望选择的颜色在每个UITableViewCell
中都相同,请在AppDelegate
中使用此选项。
let selectedView = UIView()
selectedView.backgroundColor = .white
UITableViewCell.appearance().selectedBackgroundView = selectedView
发布于 2014-09-16 22:38:52
如果您想在整个应用程序范围内进行更改,您可以将逻辑添加到您的app Delegate中
class AppDelegate: UIResponder, UIApplicationDelegate {
//... truncated
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// set up your background color view
let colorView = UIView()
colorView.backgroundColor = UIColor.yellowColor()
// use UITableViewCell.appearance() to configure
// the default appearance of all UITableViewCells in your app
UITableViewCell.appearance().selectedBackgroundView = colorView
return true
}
//... truncated
}
发布于 2015-06-15 02:22:07
为了完整性:如果您创建了自己的UITableViewCell
子类,则可以实现- (void)setSelected:(BOOL)selected animated:(BOOL)animated
方法,并设置在content视图中添加的某些视图的背景色。(如果是这样的话)或contentView本身(如果您自己的某个视图没有涉及到它)。
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
if(selected) {
self.contentView.backgroundColor = UIColor.blueColor;
} else {
self.contentView.backgroundColor = UIColor.whiteColor;
}
}
(没有用过?为了适应较小宽度的源代码DIV :)
这种方法比使用selectedBackgroundView有两个优点,它使用更少的内存和更少的CPU,除非你显示数百个单元格,否则你甚至不会注意到。
https://stackoverflow.com/questions/2553746
复制相似问题