How can I change the image displayed in a UIImageView programmatically?

If you have an IBOutlet to a UIImageView already, then all you have to do is grab an image and call setImage on the receiver (UIImageView). Two examples of grabbing an image are below. One from the Web, and one you add to your Resources folder in Xcode. UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL … 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

Fade/dissolve when changing UIImageView’s image

It can be much simpler using the new block-based, UIKit animation methods. Suppose the following code is in the view controller, and the UIImageView you want to cross-dissolve is a subview of self.view addressable via the property self.imageView Then all you need is: UIImage * toImage = [UIImage imageNamed:@”myname.png”]; [UIView transitionWithView:self.imageView duration:5.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.imageView.image … 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… }

UIImageView aspect fit and center

Just pasting the solution: Just like @manohar said imageView.contentMode = UIViewContentModeCenter; if (imageView.bounds.size.width > ((UIImage*)imagesArray[i]).size.width && imageView.bounds.size.height > ((UIImage*)imagesArray[i]).size.height) { imageView.contentMode = UIViewContentModeScaleAspectFit; } solved my problem

How to assign an action for UIImageView object in Swift

You’ll need a UITapGestureRecognizer. To set up use this: override func viewDidLoad() { super.viewDidLoad() let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:))) imageView.isUserInteractionEnabled = true imageView.addGestureRecognizer(tapGestureRecognizer) } @objc func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) { let tappedImage = tapGestureRecognizer.view as! UIImageView // Your action } (You could also use a UIButton and assign an image to it, without text … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)