How to save picture to iPhone photo library?

You can use this function: UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo); You only need completionTarget, completionSelector and contextInfo if you want to be notified when the UIImage is done saving, otherwise you can pass in nil. See the official documentation for UIImageWriteToSavedPhotosAlbum().

Convert between UIImage and Base64 string

Swift First we need to have image’s NSData //Use image name from bundle to create NSData let image : UIImage = UIImage(named:”imageNameHere”)! //Now use image to create into NSData format let imageData:NSData = UIImagePNGRepresentation(image)! //OR next possibility //Use image’s path to create NSData let url:NSURL = NSURL(string : “urlHere”)! //Now use image to create into … Read more

UIImageView missing images in Launch Screen on device

Turn it off and then on again. Seriously, restart the device — that’s what fixed it for me. Here’s what didn’t work: Cleaning DerivedData. Cleaning the project. Uninstalling the app from the device. Restarting Xcode. Restarting the computer. Older observations: Just like the others, it: Works fine in the Simulator Used to work on the … Read more

How to capture UIView to UIImage without loss of quality on retina display

Switch from use of UIGraphicsBeginImageContext to UIGraphicsBeginImageContextWithOptions (as documented on this page). Pass 0.0 for scale (the third argument) and you’ll get a context with a scale factor equal to that of the screen. UIGraphicsBeginImageContext uses a fixed scale factor of 1.0, so you’re actually getting exactly the same image on an iPhone 4 as … Read more

iOS UIImagePickerController result image orientation after upload

A UIImage has a property imageOrientation, which instructs the UIImageView and other UIImage consumers to rotate the raw image data. There’s a good chance that this flag is being saved to the exif data in the uploaded jpeg image, but the program you use to view it is not honoring that flag. To rotate the … Read more

The simplest way to resize an UIImage?

The simplest way is to set the frame of your UIImageView and set the contentMode to one of the resizing options. Or you can use this utility method, if you actually need to resize an image: + (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize { //UIGraphicsBeginImageContext(newSize); // In next line, pass 0.0 to use the current device’s pixel … Read more

How can I change image tintColor in iOS and WatchKit

iOS For an iOS app, in Swift 3, 4 or 5: theImageView.image = theImageView.image?.withRenderingMode(.alwaysTemplate) theImageView.tintColor = UIColor.red For Swift 2: theImageView.image = theImageView.image?.imageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate) theImageView.tintColor = UIColor.redColor() Meanwhile, the modern Objective-C solution is: theImageView.image = [theImageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [theImageView setTintColor:[UIColor redColor]]; Watchkit In WatchKit for Apple Watch apps, you can set the tint color for a template … Read more

Loading/Downloading image from URL on Swift

Xcode 8 or later • Swift 3 or later Synchronously: if let filePath = Bundle.main.path(forResource: “imageName”, ofType: “jpg”), let image = UIImage(contentsOfFile: filePath) { imageView.contentMode = .scaleAspectFit imageView.image = image } Asynchronously: Create a method with a completion handler to get the image data from your url func getData(from url: URL, completion: @escaping (Data?, URLResponse?, … Read more

tech