I'm using Firebase Database & Firebase Storage. I have an iOS Swift app, that allows the user to select multiple images, upload them to Firebase Storage, after the upload, it gets the downloaded URLs and stores them like:
In order to display those images in the app, I have the following xib file:
Where the middle (big) UIImageView is inside of a UIStackView because it could display more than 1 image.
My problem is that I get the URLs from the database, but for some reason I'm not able to display them in the app. I use the framework SDWebImage for caching and displaying images. So far in the app, it worked fine, but not here. I don't get where I'm wrong.
if let photoURLString = post?.photoURLs
{
for photo in photoURLString
{
let photoURL = URL(string: photo)
print(photoURL!)
postImage.sd_setImage(with: photoURL)
//postImagesStackView.addArrangedSubview(postImage)
}
}
post is the model object. I'm using for in to loop through the array of images from the database. When I print each url, I get the actual URL. But it's simple not displayed. I get this. The images are nowhere to be found/displayed:
Try to add aspect ratio for UIImage. Ex: In xib file, set ratio of UIImage to 1.
Related
I have some code that will select an image from either the user's photo library or from their camera and display it in an image view. I'm accessing the photo URL from the following line of code:
let pickedPhotoURL: URL = (info["UIImagePickerControllerImageURL"] as? URL)!
This works perfectly when accessing a photo from the user's library. However, I'll always get a nil value at this line why trying to access the photo via the camera. Anyone have any ideas / suggestions?
It's because that value isn't set for a camera. Use UIImagePickerControllerOriginalImage (or edited image if you are using that).
That key gives you a UIImage -- if you need a URL, you need to save it somewhere.
Also, don't use strings, there are keys defined for you.
I have a sticker package Stickers.xcstickers with a few stickers in it. I would like to programmatically get one of these stickers and put it in a MSStickerView that I have in a UICollectionViewCell. I know with a UIImage it is easy and you can just do
let myImage = UIImage(named: "myImage.jpg")
Is there an equivalent to this with MSSticker?
let mySticker = MSSticker(named: "mySticker") obviously does not work.
There is MSSticker(contentsOfFileURL: URL, localizedDescription: String but I am unsure how to, if possible, properly implement in a similar fashion to UIImage.
Thanks.
No, there is not currently an equivalent. Moreover, you cannot programmatically create stickers from images in an asset catalog either, since those aren't accessible through file URL (pathForResource on the bundle won't generate a path for items in an .xcassets folder).
You need to go old school and drag the images in as a resource like you would any other file you were adding to the project.
BJHStudios is right, unfortunately! I recently answered another question that you may want to take a look at. It goes over everything you need to get your stickers onto the BrowserView with the MSSticker(contentsOfFileURL: URL, localizedDescription: String) method.
Link to other question
I am writing an app that has a simple form with a photo upload tool, the user uploads their photo to the form and it is displayed in an image view, i then want that image to be in the blank e-Mail that opens up upon clicking submit. I am using the following code to try and achieve this:
let messageBody = "\n\nPhoto: \(imageView.image!)"
The photo gets uploaded and shows in the image view fine but the email displays the following where the image is supposed to be " size {1334, 70} orientation 0 scale 1.000000"
Any help would be greatly appreciated!
Your code (or my previous answer) won't work because you are converting the image to a string (messageBody). And it basically shows you a string of information about the image. So your only option is to write the message in HTML (and set isHTML to true). The good news is that it isn't too hard.
I think the code below should work.
let messageBody = "<html><body>Photo:<img src=\"yourImage.png\"></body></html>"
I'm building a keyboard extension in Swift (Xcode 7.0.1, iOS 9.0.2). Since images cannot be directly inserted into the text field, I'm using UIPasteboard to copy the image from the app and then the user would paste manually into the text field. I have already modified info.plist to give the app full permission. I initially tried
UIPasteboard.generalPasteboard().image = UIImage(named: "1.png")
but I would receive the error
changing property masksToBounds in transform-only layer, will have no effect
I wasn't able to find anything to fix this error and nothing would be pasted into the clipboard. I then tried
let image = UIImage(named: "1.png")
let data = NSData(data: UIImagePNGRepresentation(image!)!)
UIPasteboard.generalPasteboard().setData(data, forPasteboardType: "public.png")
This works perfectly for larger images, but smaller images are cropped on the right side.
1) Is there a way to programmatically resize the image as a UIImage before I send it to NSData?
2) Has anyone else experienced this issue or know why it's occurring? I'd ideally like the photos being pasted to be small but this is obviously problematic.
Thanks.
I haven't found a proper solution, but adding some transparent padding to the right edge of the image is an effective workaround.
I want to take a photo and save them within a custom album on a iPad.
I tried a lot of things but ended always with wrong image orientation.
My current procedure is:
Take photo with Xamarin.Media and safe image somewhere in my app path
Create custom album if it's not existing
Load image from temporary path and save to the album
Add the image (asset) additionally to the custom album created in 2.
The workflow above is fully working except of saving the correct orientation. After loading an image with library.AssetForUrl() the containing orientation is every time up. Also after converting from asset -> CGImage -> UImage (uiImage.Orientation).
In step 3 I tried to set the orientation the the appropriate one with
var image = new UIImage(tempImage.CGImage, 1.0f, UIImageOrientation.MyOrientation)
and also with the save command
library.WriteImageToSavedPhotosAlbum(image.CGImage, myOrientation, SaveCompletionBlock)
But the orientation is still ignored. I checked this by opening the Album application as well as loading the file in my self written gallery app.
I want to avoid the use of the iOS picker to take photos. This will produce a mess of code!
Or is there any third party library which allows to take photos and store them in a custom album? Which takes care of all the metadata information? It doesn't matter if it's written in objective-c or c#. I will create bindings for it. But it's awful to work with the camera and albums in iOS.
There are tons of hand-made UIImagePickerController alternatives. Some of them:
https://github.com/w5mith/WSAssetPickerController
https://github.com/chute/photo-picker-plus-ios
https://github.com/B-Sides/ELCImagePickerController