我正在尝试自定义一个UIButton,我希望使用UIBarButtonSystemItem样式,该样式可用于UIBarButtonItem对象。
如何在UIBarButtonSystemItem对象上使用UIBUtton样式?
发布于 2014-01-26 06:50:50
不行,UIBarButton和UIButton是两个完全不同的类。您所能做的最好是找到接近您所要寻找的图像,并将它们添加到UIButtons中。
发布于 2014-09-17 22:09:04
使用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");
}发布于 2014-01-26 09:46:58
关于UIBarButtonItem和UIButton的继承:
UIBarButtonItem->UIBarItem->NSObject
UIButton->UIControl->UIView->UIResponder->NSObject
您可以看到,在UIBarButtonSystemItem上使用UIButton、UIBarButtonItem和UIButton是不可能的,它们通常是从NSObject继承的。
https://stackoverflow.com/questions/21360545
复制相似问题