如何将按钮图标添加到自定义键盘iOS 8?

我正在为ios 8创建自定义键盘。创建这样的键盘按钮

UIButton *aBtn = [ UIButton buttonWithType:UIButtonTypeCustom ]; [aBtn setFrame:CGRectMake(x, 30, btnWidth, btnHeight)]; [aBtn setImage:[UIImage imageNamed:@"A"] forState:UIControlStateNormal]; [aBtn setTitle:@"A" forState:UIControlStateNormal]; [aBtn setTitleColor:[ UIColor blackColor] forState:UIControlStateNormal]; [aBtn setTitleColor:[ UIColor whiteColor] forState:UIControlStateHighlighted]; [aBtn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:aBtn]; 

我的问题是图像没有设置为按钮。 我怎么解决这个问题?

我是否需要任何特殊步骤才能将图像添加到Xcode以用于自定义键盘?

您可能没有将图像添加到键盘目标。

检查键盘目标>构建阶段>复制捆绑包资源以确保图像存在。 如果不是那么将它拖到那里。

请注意,我说的是键盘目标,而不是主机应用程序。 这可能是混乱。

您可以在自定义键盘上添加图像,如下面的步骤。

1.在xcode项目中添加图像

2.在键盘捆绑包资源中添加图像。 检查下图

在此处输入图像描述

3.使用按钮设置背景图像。 检查下图

在此处输入图像描述