Question

I'm using custom UIViews to as navigationBarItem (like Facebook does it in their iOS app).

UIImageView *linkesMenu = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"187menu.png"]];
UIBarButtonItem *barItem = [[UIBarButtonItem alloc] initWithCustomView:linkesMenu];

barItem.action = @selector(MenuSlider:);
self.navigationItem.leftBarButtonItem = barItem;

I tried this and a couple other things but nothing works really.

Was it helpful?

Solution

Try putting the image into a button first:

UIImage *theImage = [UIImage imageNamed:@"image.png"];
UIButton *theButton = [UIButton buttonWithType:UIButtonTypeCustom];
theButton.bounds = CGRectMake(0, 0, theImage.size.width, theImage.size.height);
[theButton setImage:theImage forState:UIControlStateNormal];
UIBarButtonItem *theBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:theButton];


[theButton addTarget:self action:@selector(MenuSlider:) forControlEvent:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = barItem;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top