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 7055425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:44:51+00:00 2026-05-28T03:44:51+00:00

A CALayer can do it, and a UIImageView can do it. Can I directly

  • 0

A CALayer can do it, and a UIImageView can do it. Can I directly display an image with aspect-fit with Core Graphics? The UIImage drawInRect does not allow me to set the resize mechanism.

  • 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-05-28T03:44:52+00:00Added an answer on May 28, 2026 at 3:44 am

    You need to do the math yourself. For example:

    // desired maximum width/height of your image
    UIImage *image = self.imageToDraw;
    CGRect imageRect = CGRectMake(10, 10, 42, 42); // desired x/y coords, with maximum width/height
    
    // calculate resize ratio, and apply to rect
    CGFloat ratio = MIN(imageRect.size.width / image.size.width, imageRect.size.height / image.size.height);
    imageRect.size.width = imageRect.size.width * ratio;
    imageRect.size.height = imageRect.size.height * ratio;
    
    // draw the image
    CGContextDrawImage(context, imageRect, image.CGImage);
    

    Alternatively, you can embed a UIImageView as a subview of your view, which gives you easy to use options for this. For similar ease of use but better performance, you can embed a layer containing the image in your view’s layer. Either of these approaches would be worthy of a separate question, if you choose to go down that route.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CALayer with some image contents. When a button touched, I want
I have made CAlayer that contains an image. What i basically want to do
I have a complex structure of CALayers forming a motion graphics system that can
I created a custom AQGridViewCell. By using UIImageView everything works. The image appears and
I am trying to add a delegate to a CALayer so I can know
Does anyone now how can I animate multiple layers at the same time using
This is my image resize code: CALayer *newCALayer = [[CALayer layer] retain]; NSImage* image
For apple said that we can't use drawRec: in a UIImageView. so I decide
I want to set the contents of a CALayer to an image. The CALayer
I have a subview in my app that contains a UIImageView. The user can

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.