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 able to figure out which one's the optimum. So here is what I think I can do.
There is a property of UITableViewCell
- accessoryView
. So I can use setAccessoryView:(UIView *)view
and pass view as the UIImageView
holding the image that I want.
I have written an utility class which creates the content view (stuff like background color, adding other stuff, etc) for my cell and I add this content view to the cell in UITableViewDelegate
. The other option is to draw a UIImage
overriding the drawRect
method of CustomContentView
utility class.
Performing option 1 - I can get the things done the apple way. Just give them the view and they do the rest. But I guess adding a new UIView
object to every row might turn out to be a heavy object allocation and decreasing the frame rate. As compared to just a UIImage
object in my contentView
. I believe UIImage
is lighter than UIView
.
Please throw some light people and help me decide over it.
A swift 3 version of the CocoaNetics solution
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 aftercell.accessoryType = .DisclosureIndicator
is set so that the disclosureIndicator button is available in the cell's subviews:In swift 3, I have adapted the solution from @galambalazs as a class extention as follows:
Hope this helps some.
benzado's solution works fine, but it showed a black background. In the UIView class that you setup (the one who's drawRect function you put in his code) needs to have the following initWithFrame implementation in order for the disclosure drawing to have a transparent background:
Naturally, you can set this to whatever color you want...
Change the tint colour of table view cell. Check the screenshot to do the same via Storyboard.
As a contribution to the solution of @benzado I swiftified his code as followed:
With a change of the app color a call to setNeedsDisplay() on the UITableCellView will update the color. I like to avoid the use of UIImage objects in cell views.