Changing the Accessory icon of a Table View

Whilst designing an iPhone application I wanted to have a very dark background colour for my Table View. I also wanted to use the standard UITableViewCellAccessory.DisclosureIndicator. However the default colour of the indicator is dark and doesn’t show up against a dark background. So I’ll just change the colour? Unfortunatley there is very little exposed to allow you to customise it, so I thought I’d blog a very quick way to make such a change;

In your table view controller override the GetCell function, this is typically a required step if you want to display data. Now you must create your own AccessoryView, this can be a complicated view, but for now let’s start with the most basic form;

RectangleF accessoryRectangle = new RectangleF(1f,1f,40f,25f);
UIView cellView = new UIView(accessoryRectangle);
cellView.BackgroundColor = new UIColor(0f,1f,0f,1f);
cell.AccessoryView = cellView;

so we now have a lovely green square, very professional. To prove you can use other assets, and to do something slighlty more useful, just use a label;

UILabel label = new UILabel(accessoryRectangle);
label.Text = ">";
cell.AccessoryView = label;

there you go, hopefully you can see that you could create as complicated a view as you want.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s