3

I have 2 images that are exactly the same, just different colors. I use them to set 2 UIImageViews images. I am trying to create a progress effect and my view hierarchy looks like this

UIView >UIImageView
       > UIView > UIImageView

All of the views are set to content mode Scale to fill other than the lowest UIImageView which is set to Left mode. This works in terms of the progress illusion if I slowly make the 2nd image (lying on top of the first) visible along the positive x axis.

The issue I have is that if I set the content mode to Left the image which should be the same has different proportions to the first image. If I set the mode for the second imageview to Scale To Fill, the images are exactly the same proportion but the image is scaled as the imageview expands along its x axis, when I would like it to be fixed.

How does one combine Scale To Fill with the Left content mode, or how could I fix this proportion issue?

some_id
  • 29,466
  • 62
  • 182
  • 304
  • 1
    Can you provide some screenshots, it is very difficult to understand the problem you are having – Dan F Aug 10 '12 at 15:39
  • I cant unfortunately. The issue is that the scaling of the image on the Scale To Fit mode is not the same as the scaling on Left mode. I would like to still use Left mode as content mode but keep the scale of the image to the same as if it was in Scale To Fit mode. – some_id Aug 10 '12 at 15:57
  • Then you need to resize your source image, or perhaps have a layer on top of the image view that is the same color as your background and slides or shrinks out of the way – Dan F Aug 10 '12 at 16:01
  • How would one apply the Scale To Fill scaling on a UIImage? – some_id Aug 10 '12 at 16:15
  • I'm not sure what you mean by your last comment, perhaps you are looking for the Aspect Fit scaling option? It will preserve the aspect ratio of the image, but fill as much of the frame as it can without spilling out. Or maybe the Aspect Fill scaling option, which will again preserve aspect ratio of the source image, but fill the image space entirely, likely ending up with some drawing outside the view's rect – Dan F Aug 10 '12 at 17:25
  • I have tried those thanks, however they, like Left, Right etc., keep the ratio. For some reason the scale to fit is changing the actual image proportions and is making my graph look better. So I am trying to go reverse and scale both to fill. This causes the issue where it scales the image as the view expands, so by 100% progress the images overlap. Setting the clipsToBounds property to yes doesnt help either. – some_id Aug 10 '12 at 17:34
  • It sounds to me like you should have something layered on top that changes size, rather than touching either image view – Dan F Aug 10 '12 at 17:35
  • The second UIVIew that holds the duplicate imageview was originally created to achieve this, and it was working when I set the imageviews.images using the drawing context's image representation. I rewrote it to cache the graphs first by storing the image representation UIImages in a dictionary as NSData objects and loading them on demand. All of a sudden it doesnt work. Also the previous setting I had on the duplicate imageview's content mode as Top Left does not apply and I had to set the mode to Left. Now it changes the actual image being drawn as well. It looks like its at a 1.5/2:1 scale. – some_id Aug 10 '12 at 17:43
  • It actually looks like the image is on the 2:1 scale on the x and y dimension when in mode Left, Right, Top Left etc. while Scale To Fit squeezes it into the frame. – some_id Aug 10 '12 at 17:56

0 Answers0