UITableView更改多个选择复选标记的颜色

时间:2014-11-18 12:11:49

标签: objective-c uitableview ios7 ios8

如何更改多项选择复选标记的色调?

我在[cell setSelectionStyle:UITableViewCellSelectionStyleGray];方法中尝试- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

但它没有效果。

我是否仅限于UITableViewCellSelectionStyle文档中定义的颜色为蓝色和灰色?

由于

2 个答案:

答案 0 :(得分:3)

请注意,在iOS 7中,使用

[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];

将无法按预期工作,因为在iOS 7中,即使您传递上面的常量,它现在也是灰色的。参见:

https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html#//apple_ref/c/tdef/UITableViewCellSelectionStyle

所以用它来改变 - (UITableViewCell *)tableView中的颜色:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法。

UIView *cellBg = [[UIView alloc] init];
cellBg.backgroundColor = [UIColor colorWithRed:(76.0/255.0) green:(161.0/255.0) blue:(255.0/255.0)     alpha:1.0]; // this RGB value for blue color
cellBg.layer.masksToBounds = YES;
Cell.selectedBackgroundView = cellBg;

答案 1 :(得分:0)

Swift 3.0

只需在cellForRowAtindexPath中设置单元格色调颜色以进行复选标记

cell.tintColor = UIColor.yourColor

并更改选择颜色集

let cellBackgroundColorView = uiview()

cellBackgroundColorView.backgroundColor = UIColor.yourColor

cell.selectedBackgroundView = cellBackgroundColorView