I'm working on an app that lets people copy and paste images. The image is copied like this:
NSString *path = [[NSBundle mainBundle] pathForResource:#"circle" ofType:#"png"];
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = [NSData dataWithContentsOfFile:path];
[pasteboard setData:data forPasteboardType:#"public.png"];
When then pasting in the Notes app, it works fine. However in the Messages app, it crops the right side of the image. Is there a way to prevent this?
You cannot prevent this, since that was Apple's UI idea. Although you can put a transparent borders into your image so even though Messages.app clips the image the main part of it still be visible.
Related
I want to copy .gif images to clipboard, so as user can paste that gif images from application to mails, etc...
I have tried :
#import MobileCoreServices;
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"http://fc05.deviantart.net/fs37/f/2008/283/a/b/KaleidoCoils_animated__gif_by_1389AD.gif"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:(__bridge NSString *)kUTTypeGIF];
What happens is the gif is "copied" but my device is no longer to paste. This might be the right code, but there might be a setting on the storyboard that I have to change in order to allow the usage of gifs and UIPasteboard.
Application https://itunes.apple.com/us/app/animated-3d-emoji+emoticons/id429348043?mt=8 already does this.
Please help me.
I am working on iOS application using new version Xcode 7 and iOS 9. I am facing the following issue.
UIImageView is not showing images coming through URL. I am using the following code but imageview did not show images.
NSURL *url = [NSURL URLWithString:#"http://XXX.XX.XX.XXX:XXXX/XXXXXXXX/7339bec316b7404299c582f5904a6d3f.jpeg"];
NSData *data = [[NSData alloc]initWithContentsOfURL:url];
UIImage *img = [[UIImage alloc]initWithData:data ];
imageview.image=img;
I don't know what is the issue in Xcode 7, but it is working previous version.
Thanks in advance,
The above code should work for synchronous loading of image into ImageView. Make sure URL and imageView code is right. Alternatively you can use SDWebImage for loading of images into imageView. It has Asynchronous loading, caching and many more options like post response processing which are very useful. It's very simple to implement too. Sample code is below.
#import <SDWebImage/UIImageView+WebCache.h>
[_profilePic sd_setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:#"placeholderIcon"]];
This will populate your imageView with a placeholder and when the image is fetched it replaces placeholder with it. Check out the github project for more options.
I'm developing a custom keyboard and I want to be able to copy the button image to clipboard (it's a png image). I've already tried something like UIPasteboard.generalPasteboard().image = UIImage(named: "dMk87zJ.png") when the button is pressed, but it doesn't work. I was only able to accomplish that with text. What am I doing wrong ?
Please use below code for copy and paste images.
NSData *data = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:data forPasteboardType:#"public.png"];
Its perfect work in all apps which allow paste functionality. Especially Notes app.
For UTI types use this link
Don't use below code
[UIPasteboard generalPasteboard].image = image;
I face issue with Notes app with this line of code to copy png image
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...
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.
If you need a library like this, feel free to check it our here:
https://github.com/danielsaidi/KeyboardKit
I am using a costum font in my eBookReader-App for a book requires it to display formulars.
The font is added to the app and most of the times it is displayed correct.
But sometimes it isn't and the formulars are display large and fat.
I have no idea why this happens. The fonts are in copied into the bundle and are available:
The css in the book looks like this:
The css is linked in each xhtml-file the webView is loading:
Why is it working most of the times but sometimes not?
You need set the url on the webview (then your app can find images and fonts from the project):
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[myWebView loadHTMLString:myHtmlString baseURL:baseURL];