6

I'm making a UITableView with expandable/collapsable cells for ios app. I put a UITableViewCellAccessoryDisclosureIndicator on these cells but I'd like to make the arrow headed up/down when the cell is expanded/collapsed.

I found that it's possible to make a button with a custom image and change the button according to the state of the cell but it seems dirty to me because I don't need a button there and I have to add 2 images to the project (ok it's not that big but anyway).

So shouldn't it be better to simply rotate the existing UITableViewCellAccessoryDisclosureIndicator ? and if so how can I do that?

Alexis
  • 16,629
  • 17
  • 62
  • 107
  • Full discussion .. http://stackoverflow.com/questions/13836606/use-table-view-disclosure-indicator-style-for-uibutton-ios – Fattie Nov 29 '13 at 07:38

1 Answers1

9

This is not exactly what you want, but this the first thing I thought of. First, instantiate a button of type UIButtonTypeDetailDisclosure:

UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

Next, rotate the button 90 degrees:

CGAffineTransform rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformRotate(rotationTransform, DegreesToRadians(90));
button.transform = rotationTransform;

Finally, use the button as the accessoryView:

cell.accessoryView = button;

Hope that helps.

Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
  • Does the use of DegressToRadians requires something special? My app doesn't compile anymore... Undefined symbols for architecture i386: "_DegreesToRadians", referenced from: – Alexis Jun 27 '12 at 10:52
  • 1
    Heh, I thought that one was pre-defined. `#define DegreesToRadians(x) (M_PI * x / 180.0)` will work for this. You can put it at the top of your file. If you use it in more than one file, you should create a Conversions.h header and put the define in there. – Jeffery Thomas Jun 27 '12 at 17:51
  • yeah finally why not simply use radians directly? M_PI/2 is just fine. – Alexis Jul 06 '12 at 09:53
  • I added a call to reload the current cell in didSelectRowForIndexPath: . Otherwise the arrow is not refreshed and doesn't change of sens – Alexis Jul 06 '12 at 09:56
  • 3
    `button.transform = CGAffineTransformMakeRotation(M_PI / 2.0f);` is a bit neater. – Mark Ingram Apr 11 '13 at 11:03
  • 7
    Fantastic answer - annoyingly in iOS7 now, the UIButtonTypeDetailDisclosure is the stupid "help symbol" ! – Fattie Nov 28 '13 at 19:31
  • 1
    But how to rotate UITableViewCellAccessoryDisclosureIndicator instead of the UIButtonTypeDetailDisclosure icon? – Gank Nov 25 '14 at 07:18
  • But how to rotate UITableViewCellAccessoryDisclosureIndicator instead of the UIButtonTypeDetailDisclosure icon? –  May 03 '17 at 11:10