简体   繁体   中英

UIBarButtonType as a UIButton. Not on a NavigationBar!

I would like to use the better styled UIBarButtonType as a typical UIButton. This is just to use on a view not a navigationBar.

I don't really want to recreate the button in an image app and apply to the various states. I know how to do it the other way around so there must be a way.

Please help.

You cannot do that. UIBarButtonItems are made just for UIToolbar and UINavigationBar. You need to create your own background image. It isn't a big issue, just few lines.

I tried this and it works :

UIButton *info = [UIButton buttonWithType:UIButtonTypeInfoLight];
UIBarButtonItem *infoBis = [[UIBarButtonItem alloc] initWithCustomView:info];
NSArray *array = [[NSArray alloc] initWithObjects:infoBis, nil];
[tool setItems:array animated:YES]; //tool = UIToolbar

don't forget to put a target on your UIBarButtonItem ;)

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