Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grandM

macrumors 68000
Original poster
Oct 14, 2013
1,551
309
Hi guys

I'm using auto layout. I put an image inside an UIImageView. This imageView is positioned using auto layout. As long as I am using a natural image all is fine. Of course when no image was provided I want to add a plus sign. This plus sign gets stretched because the imageView is using scaleToFill. So I decided to put this code inside viewDidLayoutSubViews():

Code:
self.wifeImageView.frame = CGRectMake(self.wifeImageView.frame.origin.x + self.wifeImageView.frame.height * 2/3, self.wifeImageView.frame.origin.y + self.wifeImageView.frame.height * 1/3 , self.wifeImageView.frame.height * 2/3, self.wifeImageView.frame.height * 2/3)

            }



            self.wifeImageView.contentMode = UIViewContentMode.ScaleToFill

            self.wifeImageView.clipsToBounds = true

            self.wifeImageView.image = UIImage(named: "Plus")

This code works fine. Till I rotate the device. Then it's stretched all over again. If I use the same technique inside didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) the imageView keeps getting smaller and shifting. Anyone got a suggestion how I solve the rotating part? Thanks!
 
If you're using auto layout then you don't set the frame in code. The constraints control the frame.

I recommend the tutorials on raywenderlich.com to learn auto layout.
 
If you're using auto layout then you don't set the frame in code. The constraints control the frame.

I recommend the tutorials on raywenderlich.com to learn auto layout.
Problem was the image got streched too much. I solved it by putting it a frame with a lot of whitespace. Once again my sincere thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.