如何将UIButton标识符更改为相机图标?

时间:2015-06-29 17:36:46

标签: ios xcode uibutton

使用Xcode界面构建器,我可以将UIBarButton图像图标更改为内置标识符,例如搜索图标或相机图标,如​​下所示:enter image description here

但是,我没有看到任何可以编辑常规UIButton的标识符的地方。只需点击一下UIBarButton就不可能做到这一点吗?

1 个答案:

答案 0 :(得分:4)

The 'types' are the only system equivalents for a UIButton

但是,您可以通过编程方式执行以下操作:

UIButton *cameraButton = [[UIButton alloc] init];
   cameraButton.imageView.image = [UIImage imageNamed:@"camera"];

UIBarButtonItem *camera = [[UIBarButtonItem alloc]initWithCustomView:cameraButton];
[camera setAction:@selector(doSomething)];
[camera setTarget:self];

使用您想要的相机图像创建UIButton。然后使用视图创建自定义UIBarButtonItem。 不幸的是,倒数并不那么简单。

希望这有帮助!