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

时间:2023-01-19 16:35:04

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

我正在为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];

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

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

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

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

2 个解决方案

#1


5  

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.

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

#2


1  

You can add image on custom keyboard like below steps.

1. Add images in your xcode project

2. Add images in keyboard bundle resources. check below image

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

3. Set image with background on button. check below image

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

#1


5  

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.

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

#2


1  

You can add image on custom keyboard like below steps.

1. Add images in your xcode project

2. Add images in keyboard bundle resources. check below image

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

3. Set image with background on button. check below image

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