我可以用一个UIButButtonSystemItem的UIButton?

我想要自定义一个UIButton ,我想使用UIBarButtonItem对象可用的UIBarButtonSystemItem样式。

如何在UIBUtton对象上使用UIBarButtonSystemItem样式?

你不能。 UIBarButton和UIButton是两个完全不同的类。 你可以做的最好的办法是find你想要的图像,并将它们添加到UIButtons中。

使用UIView而不是包含具有UIBarButtonItems的UIToolbar的UIButton。

 UIView *buttonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 44)]; buttonContainer.backgroundColor = [UIColor clearColor]; UIToolbar *dummyBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 80, 44)]; UIBarButtonItem *b1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(doSomething:)]; UIBarButtonItem *b2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(doSomething:)]; NSArray *items = [[NSArray alloc] initWithObjects:b1, b2, nil]; [dummyBar setItems:items]; [buttonContainer addSubview:dummyBar]; ... -(void)doSomething:(id)sender { NSLog(@"Button pushed"); } 

从UIBarButtonItem和UIButton的inheritance:

UIBarButtonItem-> UIBarItem->的NSObject

UIButton-> UIControl-> UIView-> UIResponder->的NSObject

你可以看到,UIButton上没有可能使用UIBarButtonSystemItem,UIBarButtonItem和UIButton只能从NSObjectinheritance。

你只能在导航栏的工具栏上使用它们。

一个解决方法/黑客可以使用UIToolbars你想放置UIBarButtons