首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何改变accessoryType (disclosureIndicator)的颜色?

如何改变accessoryType (disclosureIndicator)的颜色?
EN

Stack Overflow用户
提问于 2017-07-05 13:05:40
回答 7查看 11.8K关注 0票数 10

我对细胞的accessoryType有疑问。我正在使用一个带有disclosureIndicator作为accessoryType的单元格,我想改变它的颜色,但我不能。有人知道这是一个bug还是苹果强迫我使用灰色的颜色吗?实际上,我可以改变其他accessoryType的颜色。

我的代码如下所示:

代码语言:javascript
运行
复制
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier", for: indexPath) as! customCell
cell.tintColor = UIColor.red
cell.accessoryType = .disclosureIndicator

我的箭仍然是灰色的。但是如果我使用一个复选标记accessoryType,它就会变成红色。

有什么办法可以解决这个问题吗?还是我必须使用彩色图像?

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2017-07-05 13:29:20

你可以做这样的事

代码语言:javascript
运行
复制
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    cell.tintColor = UIColor.white

    let image = UIImage(named: "Arrow.png")
    let checkmark  = UIImageView(frame:CGRect(x:0, y:0, width:(image?.size.width)!, height:(image?.size.height)!));
    checkmark.image = image
    cell.accessoryView = checkmark

    let object = objects[indexPath.row] as! NSDate
    cell.textLabel!.text = object.description
    return cell
}

样本箭图像

输出

票数 18
EN

Stack Overflow用户

发布于 2020-03-24 01:46:22

使用SF符号

代码语言:javascript
运行
复制
let image = UIImage(systemName: "chevron.right")
let accessory  = UIImageView(frame:CGRect(x:0, y:0, width:(image?.size.width)!, height:(image?.size.height)!))
accessory.image = image

// set the color here
accessory.tintColor = UIColor.white
cell.accessoryView = accessory
票数 7
EN

Stack Overflow用户

发布于 2018-12-15 01:58:41

更新为SWIFT4.2,附图片

代码语言:javascript
运行
复制
    cell.accessoryType = .disclosureIndicator
    cell.tintColor = .black
    let image = UIImage(named:"disclosureArrow")?.withRenderingMode(.alwaysTemplate)
    if let width = image?.size.width, let height = image?.size.height {
        let disclosureImageView = UIImageView(frame: CGRect(x: 0, y: 0, width: width, height: height))
        disclosureImageView.image = image
        cell.accessoryView = disclosureImageView
    }

您可以使用的图像:

它可能是什么样子:

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44927146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档