UITableViewCellAccessoryType 更改复选标记颜色 [英] UITableViewCellAccessoryType Change checkmark colour

查看:25
本文介绍了UITableViewCellAccessoryType 更改复选标记颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何以编程方式(不在故事板中)为 UITableViewCellAccessoryType.Checkmark 设置颜色.

I am trying to figure out how to programmatically(not in storyboard) set the colour for UITableViewCellAccessoryType.Checkmark.

我觉得问如何做这么简单的事情有点愚蠢,但我在苹果文档中找不到答案.任何帮助都会很棒.谢谢.

I feel kinda stupid asking how to do something as simple as this, but I could not find the answer in the apple docs. Any help would be great. Thanks.

我这样设置配件类型:(工作正常)

I set the accessory type like this:(works fine)

        cell.accessoryType = .Checkmark

如果您想更改用于复选标记的图像,这对我有用.但 POB 的答案是我最终用来简单地改变颜色.

EDIT : If you want to change the image used for checkmark, this worked for me. But POB's answer is what I ended up using to simply change the colour.

    let checkImage = UIImage(named: "checkmark.png")
    let checkmark = UIImageView(image: checkImage)

    cell.accessoryView = checkmark

推荐答案

以下代码应该可以工作:

The following code should work:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell

    //Change cell's tint color
    cell.tintColor = UIColor.redColor()

    //Set UITableViewCellAccessoryType.Checkmark here if necessary
    cell.accessoryType = .Checkmark

    /* ... */

    return cell
}

这篇关于UITableViewCellAccessoryType 更改复选标记颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆