Add segmented control to navigation bar and keep title with buttons

后端 未结 8 2603
借酒劲吻你
借酒劲吻你 2020-12-04 10:03

I want to add segmented control to the navigation bar but also keep the title and buttons, like in iOS 7 Appstore purchased section (example)

I have tried adding seg

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 10:44

    My solution was this:
    Add Toolbar and Segmented control to your xib file. Customize it as you need and connect it to an outlet of your view controller:

    enter image description here

    Then, put this in the viewDidLoad method:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // add after your setup code
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:self.segmentedControl];
    
        self.navigationItem.rightBarButtonItem = item;
    }
    

    enter image description here

提交回复
热议问题