How to make a circular UIView

I can at least show you a shortcut for drawing circles of arbitrary size. No OpenGL, no Core Graphics drawing needed. Import the QuartzCore framework to get access to the .cornerRadius property of your UIView or UIImageView. #import <QuartzCore/QuartzCore.h> Also manually add it to your project’s Frameworks folder. Add this method to your view controller … Read more

“Creating an image format with an unknown type is an error” with UIImagePickerController

Below mentioned code did solve the problem for me – func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { if let image = info[UIImagePickerControllerOriginalImage] as? UIImage { imagePost.image = image } else{ print(“Something went wrong”) } self.dismiss(animated: true, completion: nil) }

How to cancel UIView block-based animation?

You can stop all animations on a view by calling: [view.layer removeAllAnimations]; (You’ll need to import the QuartzCore framework to call methods on view.layer). If you want to stop a specific animation, not all animations, your best best bet is to use CAAnimations explicitly rather than the UIView animation helper methods, then you will have … Read more

Center content of UIScrollView when smaller

I’ve got very simple solution! All you need is to update the center of your subview (imageview) while zooming in the ScrollViewDelegate. If zoomed image is smaller than scrollview then adjust subview.center else center is (0,0). – (void)scrollViewDidZoom:(UIScrollView *)scrollView { UIView *subView = [scrollView.subviews objectAtIndex:0]; CGFloat offsetX = MAX((scrollView.bounds.size.width – scrollView.contentSize.width) * 0.5, 0.0); CGFloat … Read more

UIGestureRecognizer on UIImageView

Check that userInteractionEnabled is YES on the UIImageView. Then you can add a gesture recognizer. imageView.userInteractionEnabled = YES; UIPinchGestureRecognizer *pgr = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)]; pgr.delegate = self; [imageView addGestureRecognizer:pgr]; [pgr release]; : : – (void)handlePinch:(UIPinchGestureRecognizer *)pinchGestureRecognizer { //handle pinch… }

Passing Image to another View Controller (Swift)

In prepare(for:) you can’t access the @IBOutlets of the destination view controller because they haven’t been set up yet. You should assign the image to a property of the destination view controller, and then move it into place in viewDidLoad(): In source view controller: override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == … Read more

Creating a shadow for a UIImageView that has rounded corners?

If you set clipsToBounds to true, this will round the corners but prevent the shadow from appearing. In order to resolve this, you can create two views. The container view should have the shadow, and its subview should have the rounded corners. The container view has clipsToBounds set to false, and has the shadow properties … Read more

With Auto Layout, how do I make a UIImageView’s size dynamic depending on the image?

The image view’s intrinsic size is already dependent on the size of the image. Your assumptions (and constraints are correct). However, if you’ve set up your image view in interface builder and have not provided it with an image, then the layout system (interface builder) won’t know how big your image view is supposed to … Read more