Вы можете добавить этот код в методе ViewController -viewDidLoad
:
для левой кнопки бар:
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"NavBarMapBtn.png"];
[leftButton setImage:buttonImage forState:UIControlStateNormal];
leftButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[leftButton addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
или правой кнопки бар:
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"NavBarMapBtn.png"];
[rightButton setImage:buttonImage forState:UIControlStateNormal];
rightButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[rightButton addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
Там нет необходимости добавьте BarButtonItem к вашему представлению в xib или раскадровке.
Вот что это может выглядеть следующим образом: