更改accessoryType Swift的颜色

hor*_*rst 15 uitableview accessorytype ios swift xcode6

我想将我的cell accessoryType的颜色从蓝色更改为白色.textColor已设置为白色.你们有人知道怎么做吗?

我的代码:

cell!.accessoryType = UITableViewCellAccessoryType.Checkmark

Osc*_*VGG 30

您可以将UITableViewCell tintColor属性设置为所需的颜色:

[cell setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)

  • 这是有效的.感谢您的回答!对于那些使用Swift的人来说:`cell.tintColor = UIColor.whiteColor()` (3认同)
  • 这不再起作用(在 swift 5 中测试) (2认同)

Das*_*oga 13

迅速:

cell.tintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)

Swift 3.0

cell.tintColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)

  • 如果accessoryType为.disclosureIndicator则不起作用 (3认同)

Tun*_*Fam 11

不工作.disclosureIndicator

如果有人在这里寻找“如何更改.disclosureIndicator指示器类型的颜色”。

答案是你不能。但:

有一种方法。应用自定义图像:

let chevronImageView = UIImageView(image: "disclosureIndicatorImage"))
accessoryView = chevronImageView
Run Code Online (Sandbox Code Playgroud)

其他支持链接:

该图像可以从这里下载。如何更改图像的颜色是here


Kas*_*mir 7

“如何更改.disclosureIndicator指标类型的颜色”。经过大量研究,我注意到disclosureIndicator的图像不是Image而是backgroundImage。我找到了这样的解决方案:

在此处输入图片说明

import UIKit

class CustomCell: UITableViewCell {


fileprivate func commonInit() {

}

open override func layoutSubviews() {
    super.layoutSubviews()

    if let indicatorButton = allSubviews.compactMap({ $0 as? UIButton }).last {
        let image = indicatorButton.backgroundImage(for: .normal)?.withRenderingMode(.alwaysTemplate)
        indicatorButton.setBackgroundImage(image, for: .normal)
        indicatorButton.tintColor = .red
     }
  }
}

extension UIView {
   var allSubviews: [UIView] {
      return subviews.flatMap { [$0] + $0.allSubviews }
   }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明