Chisx Chisx - 4 months ago 13
Objective-C Question

Set navigation bar title to UIBarButtonItem?

here's some code that I am using to add UIBarButtonItems to my navigation bar, how can I change it display custom images, or images uploaded to my Xcode project?

UIBarButtonItem *shareItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:nil];
UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:nil];

NSArray *actionButtonItems = @[shareItem, cameraItem];
self.navigationItem.rightBarButtonItems = actionButtonItems;

Answer
UIBarButtonItem *shareItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"your_image.png"] style:UIBarButtonItemStyleBordered target:self action:nil];
UIBarButtonItem *cameraItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"your_image.png"] style:UIBarButtonItemStyleBordered target:self action:nil];

self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects: shareItem, cameraItem, nil];

Also you can set not only your image, but also your custom UIView with method:

- (id)initWithCustomView:(UIView *)customView

See more info.