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

问题描述:

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

I am creating custom keyboard for ios 8. Creating keyboard buttons like this

    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];

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

My problem is that the image is not set to button. How can I solve this?

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

Do I need any special steps to be able to add images to Xcode for custom keyboards?

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

You probably didn't add the image to your keyboard target.

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

Check your keyboard target > Build Phases > Copy bundle resources to make sure that the image is there. Drag it there if it isn't.

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

Note that I am talking about the keyboard target, not the host app. That could be the confusion here.