在UITableView中更改选中标记的颜色。

时间:2022-11-21 21:35:01

Could someone be so kind to show me how to change the color on the checkmark in UITableView?

能不能有人好心地告诉我如何更改UITableView中的复选框上的颜色?

I have searched but don't seem to get it to work.

我找过了,但似乎没有找到工作。

Cheers

干杯

14 个解决方案

#1


43  

Apple doesn't provide a public way to change the color of the checkmark so you'll have to do it with an image.

苹果公司没有提供一种公开的方式来改变复选框的颜色,所以你必须使用图片。

This is very simple, just set the accesoryView property of the cell to a UIImageView containing a checkmark of the correct color.

这非常简单,只需将单元格的accesoryView属性设置为包含正确颜色的复选标记的UIImageView。

It'll look like this:

它会看起来像这样:

UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coloredCheckmark.png"]];
cell.accessoryView = checkmark;
[checkmark release];

Enjoy!

享受吧!

#2


185  

Since the iOS SDK has changed since the accepted answer, I thought I'd just update with a new answer.

由于iOS SDK在接受答案后发生了变化,我想我应该更新一个新的答案。

You can in fact change the color of the checkmark in a UITableViewCell by adjusting the tintColor property of the UITableViewCell.

实际上,您可以通过调整UITableViewCell的tintColor属性来更改UITableViewCell中的复选标记的颜色。

You can also set an appearance proxy for all UITableViewCells so that ALL instances have a specific tint color unless otherwise specified

您还可以为所有uitableviewcell设置一个外观代理,以便所有实例都具有特定的着色颜色,除非另有指定

[[UITableViewCell appearance] setTintColor:[UIColor redColor]];

#3


29  

The following worked for me in iOS 7.

以下内容在iOS 7中对我有用。

[self.tableView setTintColor:[UIColor someColor]];

#4


27  

If you are looking for a Swift version:

如果你正在寻找一个Swift版本:

Directly on the cell

For example in tableView(_:,cellForRowAtIndexPath:)

例如在tableView(_:cellForRowAtIndexPath:)

cell.tintColor = UIColor.redColor()

Using the appearance protocol

UITableViewCell.appearance().tintColor = UIColor.redColor()

#5


14  

This image shows how to do this in storyboards.The Tint color is the checkmark color.

这张图片展示了如何在故事板中实现这一点。颜色是选中的颜色。

在UITableView中更改选中标记的颜色。

#6


13  

I found that igraczech's answer is mostly correct, but with iOS 6 or later, you can just set the tint color of the entire tableview and default items will inherit down.

我发现igraczech的答案基本上是正确的,但是在iOS 6或更高版本中,您可以设置整个tableview的色调,默认项将继承下来。

[self.tableView setTintColor:[UIColor someColor]];

This worked for me and allowed me to color in the checkmark.

这对我起作用了,让我可以在检查标记上涂颜色。

#7


8  

Starting iOS 7 you could set the tint color of your view controller's view so that this tint colow will be propageted to all it's child views. So to set your UITableViewCell's checkmark as purple color (for example), in your viewWillAppear method you need to:

从ios7开始,你可以设置视图控制器的视图的着色颜色,这样这个着色colow将被呈现给它所有的子视图。因此,要将UITableViewCell的复选框设置为紫色(例如),需要在viewWillAppear方法中:

[self.view setTintColor:[UIColor purpleColor]];

#8


3  

The UIAccessoryTypeCheckmark (right side) inherits background color of its tableview.

UIAccessoryTypeCheckmark(右边)继承了它的tableview的背景颜色。

self.tableView.backgroundColor = [UIColor clearColor];

#9


2  

#import "UIImage+Color.h"

UIImage *image = [[UIImage imageNamed:@"ic_check_black_24dp.png"] changeColor:CLR_BUY];
UIImageView *checkmark = [[UIImageView alloc] initWithImage:image];
cell.accessoryView = checkmark;

#10


2  

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
HNCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HNCustomTableViewCell" forIndexPath:indexPath];
cell.tintColor = [UIColor colorWithRed:0.99 green:0.74 blue:0.10 alpha:1.0];
return cell;
}

It work for me.

它为我工作。

#11


2  

UITableViewCell *cell=..;
cell.tintColor=[UIColor whiteColor];
return cell;

#12


1  

You don't have to use your own image, you can simply change it in your view did load with the following code.

您不需要使用自己的映像,只需在您的视图中使用以下代码修改它。

[self.tableView setTintColor:[UIColor colorWithRed:250/255.0 green:223/255.0 blue:6/255.0 alpha:1]]

Cheers!

干杯!

#13


1  

I always used this easy way:

我总是用这种简单的方式:

UITableViewCell *cell = ...;
cell.tintColor = [UIColor greenColor];
cell.accessoryType = UITableViewCellAccessoryCheckmark;

#14


0  

Swift 3.1, iOS 9+

3.1迅速,iOS 9 +

if #available(iOS 9.0, *) {
            UIImageView.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).tintColor = UIColor.themeTint //add your color here 
        } else {
            // Fallback on earlier versions
        }

在UITableView中更改选中标记的颜色。

#1


43  

Apple doesn't provide a public way to change the color of the checkmark so you'll have to do it with an image.

苹果公司没有提供一种公开的方式来改变复选框的颜色,所以你必须使用图片。

This is very simple, just set the accesoryView property of the cell to a UIImageView containing a checkmark of the correct color.

这非常简单,只需将单元格的accesoryView属性设置为包含正确颜色的复选标记的UIImageView。

It'll look like this:

它会看起来像这样:

UIImageView *checkmark = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"coloredCheckmark.png"]];
cell.accessoryView = checkmark;
[checkmark release];

Enjoy!

享受吧!

#2


185  

Since the iOS SDK has changed since the accepted answer, I thought I'd just update with a new answer.

由于iOS SDK在接受答案后发生了变化,我想我应该更新一个新的答案。

You can in fact change the color of the checkmark in a UITableViewCell by adjusting the tintColor property of the UITableViewCell.

实际上,您可以通过调整UITableViewCell的tintColor属性来更改UITableViewCell中的复选标记的颜色。

You can also set an appearance proxy for all UITableViewCells so that ALL instances have a specific tint color unless otherwise specified

您还可以为所有uitableviewcell设置一个外观代理,以便所有实例都具有特定的着色颜色,除非另有指定

[[UITableViewCell appearance] setTintColor:[UIColor redColor]];

#3


29  

The following worked for me in iOS 7.

以下内容在iOS 7中对我有用。

[self.tableView setTintColor:[UIColor someColor]];

#4


27  

If you are looking for a Swift version:

如果你正在寻找一个Swift版本:

Directly on the cell

For example in tableView(_:,cellForRowAtIndexPath:)

例如在tableView(_:cellForRowAtIndexPath:)

cell.tintColor = UIColor.redColor()

Using the appearance protocol

UITableViewCell.appearance().tintColor = UIColor.redColor()

#5


14  

This image shows how to do this in storyboards.The Tint color is the checkmark color.

这张图片展示了如何在故事板中实现这一点。颜色是选中的颜色。

在UITableView中更改选中标记的颜色。

#6


13  

I found that igraczech's answer is mostly correct, but with iOS 6 or later, you can just set the tint color of the entire tableview and default items will inherit down.

我发现igraczech的答案基本上是正确的,但是在iOS 6或更高版本中,您可以设置整个tableview的色调,默认项将继承下来。

[self.tableView setTintColor:[UIColor someColor]];

This worked for me and allowed me to color in the checkmark.

这对我起作用了,让我可以在检查标记上涂颜色。

#7


8  

Starting iOS 7 you could set the tint color of your view controller's view so that this tint colow will be propageted to all it's child views. So to set your UITableViewCell's checkmark as purple color (for example), in your viewWillAppear method you need to:

从ios7开始,你可以设置视图控制器的视图的着色颜色,这样这个着色colow将被呈现给它所有的子视图。因此,要将UITableViewCell的复选框设置为紫色(例如),需要在viewWillAppear方法中:

[self.view setTintColor:[UIColor purpleColor]];

#8


3  

The UIAccessoryTypeCheckmark (right side) inherits background color of its tableview.

UIAccessoryTypeCheckmark(右边)继承了它的tableview的背景颜色。

self.tableView.backgroundColor = [UIColor clearColor];

#9


2  

#import "UIImage+Color.h"

UIImage *image = [[UIImage imageNamed:@"ic_check_black_24dp.png"] changeColor:CLR_BUY];
UIImageView *checkmark = [[UIImageView alloc] initWithImage:image];
cell.accessoryView = checkmark;

#10


2  

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
HNCustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HNCustomTableViewCell" forIndexPath:indexPath];
cell.tintColor = [UIColor colorWithRed:0.99 green:0.74 blue:0.10 alpha:1.0];
return cell;
}

It work for me.

它为我工作。

#11


2  

UITableViewCell *cell=..;
cell.tintColor=[UIColor whiteColor];
return cell;

#12


1  

You don't have to use your own image, you can simply change it in your view did load with the following code.

您不需要使用自己的映像,只需在您的视图中使用以下代码修改它。

[self.tableView setTintColor:[UIColor colorWithRed:250/255.0 green:223/255.0 blue:6/255.0 alpha:1]]

Cheers!

干杯!

#13


1  

I always used this easy way:

我总是用这种简单的方式:

UITableViewCell *cell = ...;
cell.tintColor = [UIColor greenColor];
cell.accessoryType = UITableViewCellAccessoryCheckmark;

#14


0  

Swift 3.1, iOS 9+

3.1迅速,iOS 9 +

if #available(iOS 9.0, *) {
            UIImageView.appearance(whenContainedInInstancesOf: [UITableViewCell.self]).tintColor = UIColor.themeTint //add your color here 
        } else {
            // Fallback on earlier versions
        }

在UITableView中更改选中标记的颜色。