Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7715177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:19:11+00:00 2026-06-01T02:19:11+00:00

I have a UIImageView that is housed inside a UIScrollView . The image in

  • 0

I have a UIImageView that is housed inside a UIScrollView. The image in the image view is bigger than the iPhone’s screen. What I want to do is have the image proportionately scaled to fit the width of the screen without changing the aspect ratio of the image (part of the image would be offscreen on the bottom).

I’ve tried using UIViewContentModeScaleAspectFill and UIViewContentModeScaleAspectFit but neither does what I want.

Any ideas?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:19:12+00:00Added an answer on June 1, 2026 at 2:19 am

    Here’s an image class I wrote to do some simple functions like this, fitInsideWidth is the function that should apply here:

    MyImage.h

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    
    @interface MyImage : NSObject
    
    + (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width covertToHeight:(float)height;
    + (UIImage*)imageWithImage:(UIImage *)image convertToHeight:(float)height;
    + (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width;
    + (UIImage*)imageWithImage:(UIImage *)image fitInsideWidth:(float)width fitInsideHeight:(float)height;
    + (UIImage*)imageWithImage:(UIImage *)image fitOutsideWidth:(float)width fitOutsideHeight:(float)height;
    + (UIImage*)imageWithImage:(UIImage *)image cropToWidth:(float)width cropToHeight:(float)height;
    
    @end
    

    MyImage.m

    #import "MyImage.h"
    
    @implementation MyImage
    
    + (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width covertToHeight:(float)height {
        CGSize size = CGSizeMake(width, height);
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext();    
        UIGraphicsEndImageContext();
        return newimage;
    }
    
    + (UIImage*)imageWithImage:(UIImage *)image convertToHeight:(float)height {
        float ratio = image.size.height / height;
        float width = image.size.width / ratio;
        CGSize size = CGSizeMake(width, height);
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext();    
        UIGraphicsEndImageContext();
        return newimage;
    }
    
    + (UIImage*)imageWithImage:(UIImage *)image convertToWidth:(float)width {
        float ratio = image.size.width / width;
        float height = image.size.height / ratio;
        CGSize size = CGSizeMake(width, height);
        UIGraphicsBeginImageContext(size);
        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
        UIImage * newimage = UIGraphicsGetImageFromCurrentImageContext();    
        UIGraphicsEndImageContext();
        return newimage;
    }
    
    + (UIImage*)imageWithImage:(UIImage *)image fitInsideWidth:(float)width fitInsideHeight:(float)height {
        if (image.size.height >= image.size.width) {
            return [MyImage imageWithImage:image convertToWidth:width];
        } else {
            return [MyImage imageWithImage:image convertToHeight:height];
        }
    }
    
    + (UIImage*)imageWithImage:(UIImage *)image fitOutsideWidth:(float)width fitOutsideHeight:(float)height {
        if (image.size.height >= image.size.width) {
            return [MyImage imageWithImage:image convertToHeight:height];
        } else {
            return [MyImage imageWithImage:image convertToWidth:width];
        }
    }
    
    + (UIImage*)imageWithImage:(UIImage *)image cropToWidth:(float)width cropToHeight:(float)height {
        CGSize size = [image size];
        CGRect rect = CGRectMake(((size.width-width) / 2.0f), ((size.height-height) / 2.0f), width, height);
        CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], rect);
        UIImage * img = [UIImage imageWithCGImage:imageRef]; 
        CGImageRelease(imageRef);
        return img;
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an UIImageView on my view. Certain parts of that image, I want
I have a UIImageView showing a image that is larger than it's frame. It's
I have a UIImageView that I allocated inside of a UIView. I want to
I have a UIImageView placed over a view and I want to capture iPhone
I have a UIImageView that displays a bigger image. It appears to be centered,
I have a UIImageView that starts off with an image (loading.png) specified in IB.
I have a UIView container that has two UIImageView s inside it, one partially
I have a UIImageView that I've added a PinchGestureRecognizer to. Currently, the image is
I have a UIImageView that I want to add a shadow behind. I wish
I have a UIImageView that is an image of the star. The problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.