开发者

Using UITabbaritem as a UIButton

开发者 https://www.devze.com 2022-12-22 23:44 出处:网络
Is there a way to use UITabbaritem as a UIButt开发者_高级运维on? 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.

Is there a way to use UITabbaritem as a UIButt开发者_高级运维on? 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.


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).


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消