Showing posts with label Navigation Bar related.... Show all posts
Showing posts with label Navigation Bar related.... Show all posts

29 Sept 2017

How to set background image to Navigation bar...



How to set background image to Navigation bar...


    UINavigationBar *navBar = self.navigationController.navigationBar;
    UIImage *img = [UIImage imageNamed:@"navImg.png"];
    [navBar setContentMode:UIViewContentModeScaleAspectFit];
    [navBar setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];

24 Jun 2017

Adding Title, Left & Right bar buttons in navigationController...


Adding Title, Left & Right bar buttons in navigationController...



- (void)viewDidLoad {

 self.title=@"VC Title";
[self showbackButton];
[self rightButton];

}


-(void)showbackButton
{

    UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
    button.titleLabel.font =[UIFont fontWithName:@"FontAwesome" size:20.0];
    [button setFrame:CGRectMake(0, 2, 30, 40)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"\uf104" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked:)];


}

// if we use fontwesome add FontAwesome.ttf file

-(void)rightButton
{

rightButton =  [[UIBarButtonItem alloc]initWithTitle:@"\uf0c9" style:UIBarButtonItemStylePlain target:self action:@selector(menuButtonClicked)];
    [rightButton setTitleTextAttributes:@{
                    NSFontAttributeName: [UIFontfontWithName:@"Fontawesome" size:15.0],
         NSForegroundColorAttributeName:[UIColor whiteColor]
} forState:UIControlStateNormal];

  self.navigationItem.rightBarButtonItems=@[rightButton];

}

31 Mar 2017

Adding a custom View (With a label & a Button)In navigation Bar rightBarButtonItem...


Adding a custom View (With a label & a Button)In navigation Bar rightBarButtonItem...

  
    UIView *containView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0,65, 40)];
    label.text = @"Out Of India";
    label.textAlignment = 1;
    label.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:11.0];
    label.textColor = [UIColor whiteColor];
    [containView addSubview:label];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(66, 0, 30, 40);
    btn.backgroundColor = [UIColor greenColor];
    [btn setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(checkSelection:) forControlEvents:UIControlEventTouchUpInside];
    [containView addSubview:btn];
    
    UIBarButtonItem *Item  = [[UIBarButtonItem alloc]initWithCustomView:containView];
    self.navigationItem.rightBarButtonItem = Item;

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");
}






2 Mar 2017

How to give A button with image or title in Navigation bar...



How to give A button with image or title in Navigation bar...

This is an example for Right bar button...


 UIImage* image3 = [UIImage imageNamed:@"ShareBtn"];
 CGRect frameimg = CGRectMake(0,0, 35,35);
 UIButton *someButton = [[UIButton alloc] initWithFrame:frameimg];
 [someButton setBackgroundImage:image3 forState:UIControlStateNormal];
 [someButton addTarget:self action:@selector(shareButtonClicked) forControlEvents:UIControlEventTouchUpInside];
//    [someButton setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *shareButton =[[UIBarButtonItem alloc] initWithCustomView:someButton];

    self.navigationItem.rightBarButtonItem=shareButton;


self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@" outdoor" style:UIBarButtonItemStylePlain target:self action:@selector(backButtonClicked:)];

Recent Posts

Codable demo

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