iPhone SDK如何在UIToolbar中使用UIButton? [英] iPhone sdk how to UIButton in UIToolbar?
本文介绍了iPhone SDK如何在UIToolbar中使用UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以通过 UIToolbar
添加 UIButton
?还是只能使用 UIBarButtonItem
?如果可以,如何在 UIToolbar
中添加 UIButton
?
Is it possible to add an UIButton
with UIToolbar
? or we can use only UIBarButtonItem
? If so how to add an UIButton
in UIToolbar
?
推荐答案
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barBackButton = [[UIBarButtonItem alloc] initWithCustomView:btn];
[toolBar setItems:[NSArray arrayWithObject:barBackButton]];
这篇关于iPhone SDK如何在UIToolbar中使用UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文