Using UITabbaritem as a UIButton
-
19-09-2019 - |
Question
Is there a way to use UITabbaritem as a UIButton? I am trying to make a Tabbar that its items don't change the view. Just want them to do simple actions in the same view controller.
Thanks.
Solution
It's probably possible, by creating a UITabBarDelegate
and implementing the correct methods, but doing so would violate Apple's HIG and cause your app to be rejected. UIToolbar
is the correct class to use for what you're describing. From that doc:
A tab bar gives users the ability to switch among different modes or views in an application, and users should be able to access these modes from everywhere in the application. However, a tab bar should never be used as a toolbar, which contains buttons that act on elements in the current mode (see “Toolbars” for more information on toolbars).
OTHER TIPS
No. It inherits from UIBarItems:NSObject. UIButton inherits from UIControl.
try this
UIButton *chatButton = [UIButton buttonWithType:UIButtonTypeCustom];
[chatButton setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateNormal];
[chatButton addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
chatButton.frame = (CGRect) {
.size.width = 30,
.size.height = 35,
};
UIBarButtonItem *barBackButton= [[UIBarButtonItem alloc] initWithCustomView:chatButton];
[navigationItem setLeftBarButtonItem:barBackButton];
NSArray *barItemArray = [[NSArray alloc]initWithObjects:navigationItem,nil];
[navigationBar setItems:barItemArray];