如何在Objective-C中创建带有图像的自定义键盘扩展? [英] How to create custom keyboard extension with images on it in Objective-C?

查看:144
本文介绍了如何在Objective-C中创建带有图像的自定义键盘扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,我想在其中创建自己的自定义键盘。



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



用户可以从设备的任何位置访问此键盘。



我希望它像这样



现在,就像我需要的那样,如果有人想要在其中添加自定义图像,您只需将图像复制到剪贴板并将图像粘贴到所需的位置即可。



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

  UIPasteboard *粘贴板= [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];

此public.png来自 http://www.escape.gr/manuals/qdrop/UTI.html



您可以选择所需的任何扩展类型。
粘贴板类型根据图片扩展名进行更改。



重要提示:对于图片发送,提供访问权限的应用粘贴从剪贴板复制的图像,仅从这些应用程序中发送图像。



我是用上述解决方案做到的。希望它也可以帮助别人。



谢谢......


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

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...

解决方案

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

Custom keyboard with extensions in objective c for ios8

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.

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

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...

这篇关于如何在Objective-C中创建带有图像的自定义键盘扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆