首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我可以用UIBarButtonSystemItem来做UIButton吗?

我可以用UIBarButtonSystemItem来做UIButton吗?
EN

Stack Overflow用户
提问于 2014-01-26 06:37:26
回答 4查看 5.2K关注 0票数 7

我正在尝试自定义一个UIButton,我希望使用UIBarButtonSystemItem样式,该样式可用于UIBarButtonItem对象。

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

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-01-26 06:50:50

不行,UIBarButton和UIButton是两个完全不同的类。您所能做的最好是找到接近您所要寻找的图像,并将它们添加到UIButtons中。

票数 8
EN

Stack Overflow用户

发布于 2014-09-17 22:09:04

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

代码语言:javascript
复制
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");
}
票数 4
EN

Stack Overflow用户

发布于 2014-01-26 09:46:58

关于UIBarButtonItem和UIButton的继承:

UIBarButtonItem->UIBarItem->NSObject

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

您可以看到,在UIBarButtonSystemItem上使用UIButton、UIBarButtonItem和UIButton是不可能的,它们通常是从NSObject继承的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21360545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档