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

  • SEARCH
  • Home
  • 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 7692583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:53:09+00:00 2026-05-31T20:53:09+00:00

I am trying to get a nice round corner on a UIImageView. I have

  • 0

I am trying to get a nice round corner on a UIImageView. I have found an implemented the following code, which works fine if the image is a square. The problem is that my imageView is a rectangular photo, sometimes portrait sometimes landscape. This code is clipping off the corners, but doesn’t give a smooth curve when one side of the image is longer than the other. Any Ideas? Also is the float in setCornerRadius applied to the image as a percentage of the sides or just straight pixel count?

    // Get the Layer of any view
    CALayer * l = [imageView layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:100.0];

Here is the fix for all interested.

Okay after some playing with it I figured out I needed to resize the imageView to fit the image. I implemented the following method to set the frame size.

- (CGRect)getScaleForFrameFromImage:(UIImage *)image
{
    // get the bigger side of image to determine the shape then
    // get the percentage we need to scale to to trim imageViewFrame 
    // so it fits image and sits in the space dedicated in main view for the image
    float percentage;
    float newWidth;
    float newHeight;

    float w = image.size.width;
    float h = image.size.height;
    if (w > h) {
        // landscape
        percentage  = 280 / w;
        newWidth = w * percentage;
        newHeight = h * percentage;;
    }
    else {
        percentage  = 208 / h;
        newWidth = w * percentage;
        newHeight = h * percentage;
    }
    int xOrigin = 20 + (280 - newWidth) / 2;
    CGRect newFrame = CGRectMake(xOrigin, 160, newWidth, newHeight);
    return newFrame;
}

then in my viewWillAppear I did this

    // set the imageFrame size
    [imageView setFrame:[self getScaleForFrameFromImage:imageToDisplay]];

    // Use that image to put on the screen in imageView
    [imageView setImage:imageToDisplay];

    // Get the Layer of imageView
    CALayer * l = [imageView layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:10.0];
  • 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-31T20:53:10+00:00Added an answer on May 31, 2026 at 8:53 pm

    What i recommend is to draw the imageView with the size of the image and then apply corner radius.

    It would be something like this.

    // get the size of the image.
    CGSize *size = yourImage.size;
    
    // use the size to set the uiimageview frame
    UIImageView * imageView = [UIImageView alloc] initWithFrame:CGRecMake(0,0,size.widht,size.height)];
     [imageView setImage:yourImage];
    //
    CALayer * l = [imageView layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:100.0];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get comfortable with jQuery and I have encountered some sample code that
First off, it is nice that they are trying to get code completion on
I am using a nice jquery slideshow plugin I found and trying to get
The scenario is trying to adjust font size to get a nice graphic arrangement,
Trying to get my mind around google protobuf. I found some implementation of protobuf
I'm trying to get Time Profiler to play nice with me. I am able
I'm trying to get QtJambi and Jython to play nice together. Here's what I'm
I'm trying to get git up running on a Windows server. I have installed
I'm trying to get the percentage of each video I have in my database

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.