How to programmatically add a UINavigationBar and a back button on it

前端 未结 2 848
抹茶落季
抹茶落季 2021-01-21 06:07

I am newbie trying to make an app similar to Notes app of iPhone using UITextView. I am getting the textView and lines and it is working fine.

相关标签:
2条回答
  • 2021-01-21 06:18

    use this code....

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
                                      initWithTitle:NSLocalizedString(@"Back", @"")
                                      style:UIBarButtonItemStyleDone
                                      target:self
                                      action:@selector(YourActionMethod:)];
    
    
    self.navigationItem.leftBarButtonItem = addButton;
    
    0 讨论(0)
  • 2021-01-21 06:27

    Navigation Bar Image

    UINavigationBar *navBar = [[self navigationController] navigationBar];
        UIImage *image = [UIImage imageNamed:@"TopBar.png"];
        [navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];  
    

    Back Button

    -(void)getBackBtn
    {
        UIButton *Btn =[UIButton buttonWithType:UIButtonTypeCustom];
    
        [Btn setFrame:CGRectMake(0.0f,0.0f,50.0f,30.0f)];
        [Btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"back.png"]]  forState:UIControlStateNormal];
        //[Btn setTitle:@"OK" forState:UIControlStateNormal];
        //Btn.titleLabel.font = [UIFont fontWithName:@"Georgia" size:14];
        [Btn addTarget:self action:@selector(backBtnPress:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:Btn];
        [self.navigationItem setLeftBarButtonItem:addButton];
    }  
    

    BackButtonAction

    -(IBAction)backBtnPress:(id)sender
    {
    }  
    

    View on NavigationBar

    For View on navigationBar you can follow my answer Link

    0 讨论(0)
提交回复
热议问题