[IOS]navigation bar change button and title

1. Change button

On the parent page:

UIBarButtonItem *backBtn = [[UIBarButtonItem alloc]init];
    backBtn.title = @"xxxx";
    self.navigationItem.backBarButtonItem = backBtn;

 

2. Change the title:

On subpages:

UInavigationItem *navItem = self.navigationItem;
navItem.title = @"My Device";

 

3. Cancel the back button

navItem.hidesBackButton = YES;

 

4. Change the navigation bar color:

self.navigationController.navigationBar.barTintColor = [UIColor lightGrayColor];

 

5. Set the back button event

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
                                              initWithTitle:@"return"
                                              style:UIBarButtonItemStylePlain
                                              target:self
                                              action:@selector(GoBack:)]
                                              autorelease];

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326249121&siteId=291194637
Recommended