cfisher cfisher - 4 months ago 15x
Objective-C Question

Adding a UISwitch to a UINavigationItem

I want to have a UISwitch in the right corner of a UINavigationItem, instead of a UIBarButton. Is this possible without subclassing the UINavigationItem?


You can create a UIBarButtonItem with a custom view inside it by using the initWithCustomView: method. For example:

UISwitch *switch = ...;
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:mySwitch];

Set this as the left/right item on your UINavigationItem.