如何在Objective-C中创建带有图像的自定义键盘扩展?

时间:2022-09-07 11:12:20

I am having an app in which I want to create my own custom keyboard.

我有一个应用,我想创建我自己的自定义键盘。

In this custom keyboard, I want to put images.

在这个自定义键盘中,我想要放置图像。

Users can access this keyboard from anywhere in the device.

用户可以从设备的任何地方访问这个键盘。

I want it like this Link.

我想要这个链接。

I want to make a keyboard like this 如何在Objective-C中创建带有图像的自定义键盘扩展?

我想做一个这样的键盘。

I have searched a lot on this and I know there are lots of tutorials but most of those are in swift and another are not with keyboard extension.

我已经搜索了很多,我知道有很多的教程,但是大部分都是快速的,另外一个不是用键盘扩展。

I want proper guidance or any link of tutorial for this.

我需要适当的指导或任何教程的链接。

Any help would be highly appreciated.

非常感谢您的帮助。

Thanks...

谢谢……

2 个解决方案

#1


6  

So I got my answer from the below link which is a very nice tutorial in objective C.

我从下面的链接中得到了答案这是objective C中的一个很好的教程。

Custom keyboard with extensions in objective c for ios8

为ios8在objective c中添加扩展的自定义键盘

Now, like I needed, if anyone wants to add custom images in it, you can just copy the image to the clipboard and paste the image where its needed.

现在,就像我需要的,如果有人想要添加自定义图像,你可以将图像复制到剪贴板中,并将图像粘贴到需要的地方。

For copying the png files, use the below code.

要复制png文件,请使用下面的代码。

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *imageName = [NSString stringWithFormat:@"%ld",(long)sender.tag];
NSString *newPathName = [[NSBundle mainBundle]pathForResource:imageName ofType:@"png"];
NSData *data = [NSData dataWithContentsOfFile:newPathName];
[pasteboard setData:data forPasteboardType:@"public.png"];

This public.png comes from http://www.escape.gr/manuals/qdrop/UTI.html

这个公共。png来自http://www.escape.gr/manuals/qdrop/UTI.html

You can choose any extension type you want to. The pasteboard type changes as per the image extensions.

您可以选择任何您想要的扩展类型。粘贴板类型会随着图像扩展而改变。

Important note: For image sending, the Apps which gives an access to paste the image copied from clipboard, only from those apps images will be sent.

重要提示:对于图像发送,提供粘贴从剪贴板拷贝的图像的应用程序,只会发送来自这些应用程序的图像。

I did it with the above solutions. Hope it helps someone else also.

我用上面的解算出来了。希望它也能帮助别人。

Thanks...

谢谢……

#2


1  

This question is several years old now, but if anyone has the same needs today, I have created a Swift library that helps you create keyboard extensions that support characters, operations like backspace, newline etc. as well as images. It also has support for copying images to the pasteboard and saving them to the photo album.

这个问题已经有好几年的历史了,但如果今天有人有同样的需求,我已经创建了一个Swift库,它可以帮助您创建支持字符、backspace、newline等操作以及图像的键盘扩展。它还支持将图像复制到粘贴板并保存到相册中。

If you need a library like this, feel free to check it our here:

如果你需要像这样的图书馆,请在我们的这里查看:

https://github.com/danielsaidi/KeyboardKit

https://github.com/danielsaidi/KeyboardKit

#1


6  

So I got my answer from the below link which is a very nice tutorial in objective C.

我从下面的链接中得到了答案这是objective C中的一个很好的教程。

Custom keyboard with extensions in objective c for ios8

为ios8在objective c中添加扩展的自定义键盘

Now, like I needed, if anyone wants to add custom images in it, you can just copy the image to the clipboard and paste the image where its needed.

现在,就像我需要的,如果有人想要添加自定义图像,你可以将图像复制到剪贴板中,并将图像粘贴到需要的地方。

For copying the png files, use the below code.

要复制png文件,请使用下面的代码。

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *imageName = [NSString stringWithFormat:@"%ld",(long)sender.tag];
NSString *newPathName = [[NSBundle mainBundle]pathForResource:imageName ofType:@"png"];
NSData *data = [NSData dataWithContentsOfFile:newPathName];
[pasteboard setData:data forPasteboardType:@"public.png"];

This public.png comes from http://www.escape.gr/manuals/qdrop/UTI.html

这个公共。png来自http://www.escape.gr/manuals/qdrop/UTI.html

You can choose any extension type you want to. The pasteboard type changes as per the image extensions.

您可以选择任何您想要的扩展类型。粘贴板类型会随着图像扩展而改变。

Important note: For image sending, the Apps which gives an access to paste the image copied from clipboard, only from those apps images will be sent.

重要提示:对于图像发送,提供粘贴从剪贴板拷贝的图像的应用程序,只会发送来自这些应用程序的图像。

I did it with the above solutions. Hope it helps someone else also.

我用上面的解算出来了。希望它也能帮助别人。

Thanks...

谢谢……

#2


1  

This question is several years old now, but if anyone has the same needs today, I have created a Swift library that helps you create keyboard extensions that support characters, operations like backspace, newline etc. as well as images. It also has support for copying images to the pasteboard and saving them to the photo album.

这个问题已经有好几年的历史了,但如果今天有人有同样的需求,我已经创建了一个Swift库,它可以帮助您创建支持字符、backspace、newline等操作以及图像的键盘扩展。它还支持将图像复制到粘贴板并保存到相册中。

If you need a library like this, feel free to check it our here:

如果你需要像这样的图书馆,请在我们的这里查看:

https://github.com/danielsaidi/KeyboardKit

https://github.com/danielsaidi/KeyboardKit