The bottom bar in the UINavigationController is typically known as tool bar. It can be customized with setToolbarItems using an array of UIBarButtonItem.
1. Usually the best place to add the customization code for adding the UINavigationBarItem and UIToolBarItems is in the viewDidLoad method of the UIViewController.
2. To add the UINavigationBarItem,
a) First create an UIBarButtonItem
Eg: the below code implement system button
UIBarButtonItem *butt = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemCarmera
target:self action:@selector(action)];
b) Add the newly created custom button to the navigation bar:initWithBarButtonSystemItem: UIBarButtonSystemItemCarmera
target:self action:@selector(action)];
Eg:
self.navigationItem.rightBarButtonItem = butt;
// or [self.navigationItem setRightBarButtonItem:butt animated:YES];
// or [self.navigationItem setRightBarButtonItem:butt animated:YES];
3. If back button is needed in all subsequence pushed viewController (to return to parent view),
the backBarButtonItem is needed to add to the root navigationController. If the title of the
backBarButtonItem is not set, the default behaviour is that the back button will be created with
the title of the parent view.
**Note: For default behaviour to work, all the viewController must be set with a title.
Eg:
UIBarButtonItem *backButt = [[UIBarButtonItem alloc]init];
[backButt setTitle:@"Back"];
[self.navigationItem setBackBarButtonItem:backButt];
[backButt setTitle:@"Back"];
[self.navigationItem setBackBarButtonItem:backButt];
4. To add the UIToolbarItems,
a) First create all the individual needed UIBarButtonItem
Eg: Below code create the system's action and compose button, and a custom information button
Note: the custom information button does not work in the navigation bar
UIBarButtonItem *butt1 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self action:@selector(getInfo:)];
UIBarButtonItem *butt2 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:self action:@selector(getInfo:)];
/* Below code create other system button, such as Info Button */
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
[infoButton addTarget:self action:@selector(action)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *butt3 = [[UIBarButtonItem alloc] initWithCustomView: infoButton];
/*** Below code add a button with image **/
UIButton* starButt =[UIButton buttonWithType:UIButtonTypeCustom];
UIImage* buttonImage = [UIImage imageNamed:@"star.png"];
[starButt addTarget:self action:@selector(getInfo:)
forControlEvents:UIControlEventTouchUpInside];
[starButt setImage:buttonImage forState:UIControlStateNormal];
starButt.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
UIBarButtonItem *butt4 = [[UIBarButtonItem alloc]initWithCustomView:starButt];
b) Create an array for all the above created UIBarButtonItems.initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self action:@selector(getInfo:)];
UIBarButtonItem *butt2 = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
target:self action:@selector(getInfo:)];
/* Below code create other system button, such as Info Button */
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoDark];
[infoButton addTarget:self action:@selector(action)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *butt3 = [[UIBarButtonItem alloc] initWithCustomView: infoButton];
/*** Below code add a button with image **/
UIButton* starButt =[UIButton buttonWithType:UIButtonTypeCustom];
UIImage* buttonImage = [UIImage imageNamed:@"star.png"];
[starButt addTarget:self action:@selector(getInfo:)
forControlEvents:UIControlEventTouchUpInside];
[starButt setImage:buttonImage forState:UIControlStateNormal];
starButt.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
UIBarButtonItem *butt4 = [[UIBarButtonItem alloc]initWithCustomView:starButt];
eg.
NSArray* toolBarItems = [NSArray arrayWithObjects:butt1,butt2,butt3,butt4,nil];
c) Release all the create UIBarButtonItemseg.
[toolBarItems makeObjectsPerformSelector:@selector(release)];
d) Assign the newly created UIBarButtonItem array to the toolBarItems and set it to not hidden (by default it is hidden) :
eg.
[self setToolbarItems:toolBarItems animated:YES]; // or self.toolbarItems = toolBarItems;
[self.navigationController setToolbarHidden:NO]; //or self.navigationController.toolbarHidden= NO;
[self.navigationController setToolbarHidden:NO]; //or self.navigationController.toolbarHidden= NO;
5. Implement the method to handle when the button is clicked.
eg.
- (void)action {
// ... actual code to implement the action
// ... when the button is clicked
}
// ... actual code to implement the action
// ... when the button is clicked
}
Nice and very helpful information i have got from your post. Even your whole blog is full of interesting information which is the great sign of a great blogger.
ReplyDeleteLenovo - IdeaPad 15.6" Laptop - 6GB Memory - 1TB Hard Drive - Dark Chocolate
Lenovo - 14" Notebook - 4 GB Memory - 320 GB Hard Drive - Black
The information you have posted is very useful. The sites you have referred was good. Thanks for sharing.. https://iphoneappdevelopmentcompany.com/
ReplyDeletemmorpg oyunlar
ReplyDeleteinstagram takipçi satın al
Tiktok jeton hilesi
TİKTOK JETON HİLESİ
antalya saç ekimi
Referans kimliği nedir
instagram takipçi satın al
metin2 pvp serverlar
metin2 pvp serverlar
instagram takipçi satın al
perde modelleri
ReplyDeletemobil ödeme bozdurma
NFT NASİL ALİNİR
ankara evden eve nakliyat
dedektör
web sitesi kurma
Ask Kitaplari
smm panel
ReplyDeleteSmm panel
iş ilanları
İNSTAGRAM TAKİPÇİ SATIN AL
HIRDAVATÇI BURADA
beyazesyateknikservisi.com.tr
servis
tiktok jeton hilesi
pendik daikin klima servisi
ReplyDeleteüsküdar beko klima servisi
pendik lg klima servisi
pendik alarko carrier klima servisi
tuzla toshiba klima servisi
ümraniye alarko carrier klima servisi
beykoz samsung klima servisi
üsküdar samsung klima servisi
beykoz mitsubishi klima servisi