Thursday, 5 June 2014

Add UIBarButtonItem on NavigationBar

a) UIBarButtonItem *btn = [[UIBarButtonItem alloc]
                                initWithTitle:@"Add"
                                style:UIBarButtonItemStyleBordered
                                target:self
                                action:@selector(buttonAddClick)];
    
    self.navigationItem.rightBarButtonItem = btn;



b) UIBarButtonItem * btn = [[UIBarButtonItem alloc]
                                  initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                  target:self action:@selector(buttonAddClick)];
    
    self.navigationItem.rightBarButtonItem = btn;



c) UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];

    btn.frame = CGRectMake(0, 0, 30, 30);

    [btn setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];

    //[btn setImage:[UIImage imageNamed:@"logout-hover"] forState:UIControlStateHighlighted];

    [btn addTarget:self action:@selector(buttonAddClick) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView: btn];

    self.navigationItem.rightBarButtonItem = rightBarButtonItem;

No comments:

Post a Comment