28 Mar 2017

NavigationBar With Multiple Buttons Programmatically...



NavigationBar With Multiple Buttons Programmatically...



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UINavigationBar *myNav = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    [UINavigationBar appearance].barTintColor = [UIColor lightGrayColor];
    [self.view addSubview:myNav];
    
    
    UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel"
                                                                   style:UIBarButtonItemStylePlain
                                                                  target:self
                                                                  action:@selector(cancelAction)];
    
   
    
    UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                 style:UIBarButtonItemStylePlain
                                                                target:self action:@selector(doneAction)];
    
    
    UINavigationItem *navigItem = [[UINavigationItem alloc] initWithTitle:@"Navigation Title"];
    myNav.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor greenColor]};
    
    navigItem.rightBarButtonItem = doneItem;
    navigItem.leftBarButtonItem = cancelItem;
    
    
    UIBarButtonItem *email = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(emailAction)];
    
    navigItem.leftBarButtonItems = [navigItem.leftBarButtonItems arrayByAddingObject:email];
    
    
    UIBarButtonItem *camera = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(cameraAction)];
    navigItem.rightBarButtonItems = [navigItem.rightBarButtonItems arrayByAddingObject:camera];
    
    myNav.items = [NSArray arrayWithObjects: navigItem,nil];
    
    camera.tintColor = [UIColor greenColor];
    email.tintColor = [UIColor redColor];
    camera.tintColor = [UIColor purpleColor];
    [UIBarButtonItem appearance].tintColor = [UIColor blueColor];
    

// To add images -
    
   // UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,10,32,32)];
   // [myImage setImage:[UIImage imageNamed:@"image.png"]];
   // self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myImage];
   //   [self.view addSubview:myImage];
    
}


- (void) cancelAction {
    
    NSLog(@"Cancel Button Clicked");
}


- (void) emailAction {
    
    NSLog(@"Email Button Clicked");
}
    
- (void) cameraAction {
    
   NSLog(@"Camera Button Clicked");
}

- (void) doneAction {
    
    NSLog(@"Done Button Clicked");
}






No comments:

Post a Comment

Recent Posts

Codable demo

Link: https://www.dropbox.com/s/kw7c1kgv1628bh7/codableDemo.zip?dl=0