I am changing my view controller using the following code:
[self.slidingViewController performSegueWithIdentifier:@"FindScoresController" sender:self.slidingViewController];
The segue is PUSH
Now I want to add UINavigationBar
Programatically. The code i am using for it is:
// Not required if viewController is pushed from previous viewController
UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
UIColor *barColor = [[UIColor alloc]initWithRed:82/255.0f green:167/255.0f blue:192/255.0f alpha:1.0f];
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// iOS 6.1 or earlier
navbar.tintColor = barColor;
} else {
// iOS 7.0 or later
navbar.barTintColor = barColor;
navbar.translucent = NO;
}
[self.view addSubview:navbar];
It adds nav bar successfully. Now I want to add left and right custom buttons with custom Image. But I am unable to do so.
Code i am using to add right UIBarButton
item:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:@"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(flipView:)];
self.navigationItem.rightBarButtonItem = flipButton;
But it doesn't show any effect.
I also tried this code:
UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourimage2.jpg"]]];
self.navigationItem.rightBarButtonItem = item;
All these code i am writing in ViewDidLoad
method.