Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 951
cfischer Avatar asked Dec 12 '22 16:12

cfischer


1 Answers

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.

like image 139
Mike Weller Avatar answered Jan 01 '23 05:01

Mike Weller