Change font of back navigation bar button

前端 未结 7 1134
走了就别回头了
走了就别回头了 2020-12-04 17:38

I want to be able to set the font of my apps navigation bar back button without doing anything too crazy and without losing any other design characteristics of the button (i

7条回答
  •  醉酒成梦
    2020-12-04 18:22

    If you're using the new UISplitViewControllerDelegate for split views in iOS 8, the above methods won't work because the new displayModeButtonItem works a bit differently.

    You need to set the font when you're creating the displayModeButtonItem. Assuming you're following Apple's templates this is probably in prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender where you would do something like this:

    // From Apple's Template:
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
    DetailViewController *controller = (DetailViewController *)[[segue destinationViewController] topViewController];
    [controller setDetailItem:object];
    controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
    controller.navigationItem.leftItemsSupplementBackButton = YES;
    // New Line to set the font:
    [controller.navigationItem.leftBarButtonItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"SourceSansPro-Regular" size:14]} forState:UIControlStateNormal];
    

提交回复
热议问题