I have a simple project where I have a image that needs to be put into a viewcontroller and then added to the main view. The code works fine, but even though the content mode has been set UIViewContentModeScaleAspectFit , I don’t see the image scaled correctly. It appears stretched and clipped.
What am I doing wrong here?
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIViewController *controller = [[UIViewController alloc] init];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"a.jpg"]];
imgView.contentMode = UIViewContentModeScaleAspectFit;
[controller.view addSubview:imgView];
[self.view addSubview:controller.view];
}
Solved the problm by creating a view using storyboard, linking it via IBOutlets and then loading the image. For whatever reason, assigning the imageview in the above mentioned way does not change its properties once set.