Draw custom Back button on iPhone Navigation Bar

前端 未结 2 879
夕颜
夕颜 2020-12-09 20:01

I\'ve got a UIView with a NavigationBar and I\'d like to add a button which looks like the style of a Back Button. I\'m not using a UINavigationController and was wondering

相关标签:
2条回答
  • 2020-12-09 20:44

    You need to set up a custom stack of UINavigationItem objects and push them on to the UINavigationBar. This is the only way I know of to get a true back button. I haven't tested this code, but you should do something like this:

    UINavigationItem *previousItem =
        [[[UINavigationItem alloc] initWithTitle:@"Back title"] autorelease];
    
    UINavigationItem *currentItem =
        [[[UINavigationItem alloc] initWithTitle:@"Main Title"] autorelease];
    
    [navigationBar setItems:[NSArray arrayWithObjects:previousItem, currentItem, nil]
                   animated:YES];
    

    To handle when the buttons are pressed you should set yourself as the navigation bar's delegate and implement the UINavigationBarDelegate delegates.

    0 讨论(0)
  • 2020-12-09 20:52

    You can also update this by modifying the backBarButtonItem on the previous view controller (not the currently viewed one).

    0 讨论(0)
提交回复
热议问题