Question

I have problems with the ScaletoFit method. I Have a UIPageViewController with a UIImagesView and want to show different pictures in it, but it does not work as it should.

With these two lines I initialize the picture.

self.screenPicture.image = [UIImage imageNamed:@"1.png"];
self.screenPicture.contentMode = UIViewContentModeScaleAspectFit;

it's build in a case structure, which decides what picture the user can see.

switch(self.index)
    {
        case zero: {
            self.screenNumber.text = [NSString stringWithFormat:@"1.", nil];
            self.screenPicture.image = [UIImage imageNamed:@"1.png"];
            self.screenPicture.contentMode = UIViewContentModeScaleAspectFit;
            NSLog(@"%d",self.index);
            break;
        }
        case one: {
            self.screenNumber.text = [NSString stringWithFormat:@"2.", nil];
            self.screenPicture.image = [UIImage imageNamed:@"2.png"];
            self.screenPicture.contentMode = UIViewContentModeScaleAspectFit;
            NSLog(@"%d",self.index);
            break;
        }
        case two: {
            self.screenNumber.text = [NSString stringWithFormat:@"3.", nil];
            self.screenPicture.image = [UIImage imageNamed:@"3.png"];
            self.screenPicture.contentMode = UIViewContentModeScaleAspectFit;
            NSLog(@"%d",self.index);
            break;
        }
        case three: {
            self.screenNumber.text = [NSString stringWithFormat:@"4.", nil];
            self.screenPicture.image = [UIImage imageNamed:@"4.png"];
            self.screenPicture.contentMode = UIViewContentModeScaleAspectFit;
            NSLog(@"%d",self.index);
            break;
        }
        default: {
            self.screenNumber.text = [NSString stringWithFormat:@"5.", nil];
            self.screenPicture.image = [UIImage imageNamed:@"5.png"];
            self.screenPicture.contentMode = UIViewContentModeScaleAspectFit;
            NSLog(@"%d",self.index);
            break;
        }
    }

In the App the picture is now in the original size, which is too big. Why is the ScaleAspectFit-Method not working?

can somebody help me?

Thanks:)

Was it helpful?

Solution

According to the iOS Developer Library:

The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change.

...and not the other way around. You seem to want to resize the view based on its content, but contentMode does the opposite.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top