I need to change the color of the disclosureIndicatorView
accessory in a UITableViewCell
.
I think there are two ways to get this done, but I\'m not
While galambalazs' answer works, it should be noted that it is somewhat of a hack as it indirectly accesses and updates Apple's private implementation of the disclosure indicator. At best, it could stop working in future iOS releases, and at worst lead to App Store rejection. Setting the accessoryView
is still the approved method until Apple exposes a property for directly setting the color.
Regardless, here is the Swift implementation of his answer for those who may want it:
Note: cell.disclosureIndicatorColor
has to be set after cell.accessoryType = .DisclosureIndicator
is set so that the disclosureIndicator button is available in the cell's subviews:
extension UITableViewCell {
public var disclosureIndicatorColor: UIColor? {
get {
return arrowButton?.tintColor
}
set {
var image = arrowButton?.backgroundImageForState(.Normal)
image = image?.imageWithRenderingMode(.AlwaysTemplate)
arrowButton?.tintColor = newValue
arrowButton?.setBackgroundImage(image, forState: .Normal)
}
}
public func updateDisclosureIndicatorColorToTintColor() {
self.disclosureIndicatorColor = self.window?.tintColor
}
private var arrowButton: UIButton? {
var buttonView: UIButton?
self.subviews.forEach { (view) in
if view is UIButton {
buttonView = view as? UIButton
return
}
}
return buttonView
}
}