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

How to change UIButton Identifier to Camera Icon?

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

但是,我看不到任何可以编辑常规 UIButton 标识符的地方。是不是根本不可能像UIBarButton那样一键搞定?

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

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。 不幸的是,逆向并不那么简单。

希望对您有所帮助!