简体   繁体   中英

Add button to top UITabBarController

I have an app which has a UITabBarController as rootviewcontroller. The UITabBarController has four items. The four UIViewConotrollers are embedded in UINavigationControllers. I can add a button or image on the UINavigationController. However, I have to repeat 4 times on each UINavigationController for the same button or image. Is it possible I can add a button or image on the top of UITabBarController which is set as rootviewcontroller? Thanks in advance.

Theoretically, you can do it by:

UIButton *button = ; // your button
button.frame = CGRect(...); // position on the screen, where you want to have the button

[rootViewController addSubview:button];

However, this solution is strongly not recommended.

What you can do instead, is to create an abstract class MyViewControllerWithButton : UIViewController which will implement viewDidAppear: creation of UIButton and adding it to the navigationBar.

All the viewControllers that you use in tab bars will be a subclass of MyViewControllerWithButton.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM