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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:12:27+00:00 2026-05-13T23:12:27+00:00

In my application – there are four buttons named as follows: Top – left

  • 0

In my application – there are four buttons named as follows:

  • Top – left
  • Bottom – left
  • Top – right
  • Bottom – right

Above the buttons there is an image view (or a UIView).

Now, suppose a user taps on – top – left button. Above image / view should be rounded at that particular corner.

I am having some difficulty in applying rounded corners to the UIView.

Right now I am using the following code to apply the rounded corners to each view:

    // imgVUserImg is a image view on IB.
    imgVUserImg.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"any Url Here"];
    CALayer *l = [imgVUserImg layer];
    [l setMasksToBounds:YES];
    [l setCornerRadius:5.0];  
    [l setBorderWidth:2.0];
    [l setBorderColor:[[UIColor darkGrayColor] CGColor]];

Above code is applying the roundness to each of corners of supplied View. Instead I just wanted to apply roundness to selected corners like – top / top+left / bottom+right etc.

Is it possible? How?

  • 1 1 Answer
  • 1 View
  • 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-13T23:12:28+00:00Added an answer on May 13, 2026 at 11:12 pm

    I used the answer over at How do I create a round cornered UILabel on the iPhone? and the code from How is a rounded rect view with transparency done on iphone? to make this code.

    Then I realized I’d answered the wrong question (gave a rounded UILabel instead of UIImage) so I used this code to change it:

    http://discussions.apple.com/thread.jspa?threadID=1683876

    Make an iPhone project with the View template. In the view controller, add this:

    - (void)viewDidLoad
    {
        CGRect rect = CGRectMake(10, 10, 200, 100);
        MyView *myView = [[MyView alloc] initWithFrame:rect];
        [self.view addSubview:myView];
        [super viewDidLoad];
    }
    

    MyView is just a UIImageView subclass:

    @interface MyView : UIImageView
    {
    }
    

    I’d never used graphics contexts before, but I managed to hobble together this code. It’s missing the code for two of the corners. If you read the code, you can see how I implemented this (by deleting some of the CGContextAddArc calls, and deleting some of the radius values in the code. The code for all corners is there, so use that as a starting point and delete the parts that create corners you don’t need. Note that you can make rectangles with 2 or 3 rounded corners too if you want.

    The code’s not perfect, but I’m sure you can tidy it up a little bit.

    static void addRoundedRectToPath(CGContextRef context, CGRect rect, float radius, int roundedCornerPosition)
    {
    
        // all corners rounded
        //  CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + radius);
        //  CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height - radius);
        //  CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, 
        //                  radius, M_PI / 4, M_PI / 2, 1);
        //  CGContextAddLineToPoint(context, rect.origin.x + rect.size.width - radius, 
        //                          rect.origin.y + rect.size.height);
        //  CGContextAddArc(context, rect.origin.x + rect.size.width - radius, 
        //                  rect.origin.y + rect.size.height - radius, radius, M_PI / 2, 0.0f, 1);
        //  CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + radius);
        //  CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + radius, 
        //                  radius, 0.0f, -M_PI / 2, 1);
        //  CGContextAddLineToPoint(context, rect.origin.x + radius, rect.origin.y);
        //  CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + radius, radius, 
        //                  -M_PI / 2, M_PI, 1);
    
        // top left
        if (roundedCornerPosition == 1) {
            CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + radius);
            CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height - radius);
            CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, 
                            radius, M_PI / 4, M_PI / 2, 1);
            CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, 
                                    rect.origin.y + rect.size.height);
            CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y);
            CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y);
        }   
    
        // bottom left
        if (roundedCornerPosition == 2) {
            CGContextMoveToPoint(context, rect.origin.x, rect.origin.y);
            CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height);
            CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, 
                                    rect.origin.y + rect.size.height);
            CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y);
            CGContextAddLineToPoint(context, rect.origin.x + radius, rect.origin.y);
            CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + radius, radius, 
                            -M_PI / 2, M_PI, 1);
        }
    
        // add the other corners here
    
    
        CGContextClosePath(context);
        CGContextRestoreGState(context);
    }
    
    
    -(UIImage *)setImage
    {
        UIImage *img = [UIImage imageNamed:@"my_image.png"];
        int w = img.size.width;
        int h = img.size.height;
    
        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst);
    
        CGContextBeginPath(context);
        CGRect rect = CGRectMake(0, 0, w, h);
    
    
        addRoundedRectToPath(context, rect, 50, 1);
        CGContextClosePath(context);
        CGContextClip(context);
    
        CGContextDrawImage(context, rect, img.CGImage);
    
        CGImageRef imageMasked = CGBitmapContextCreateImage(context);
        CGContextRelease(context);
        CGColorSpaceRelease(colorSpace);
        [img release];
    
        return [UIImage imageWithCGImage:imageMasked];
    }
    

    alt text http://nevan.net/skitch/skitched-20100224-092237.png

    Don’t forget that you’ll need to get the QuartzCore framework in there for this to work.

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

Sidebar

Related Questions

Application : It has 3 views Views A,B,C. There is a Alert on View
Application, have a TextBlock and two Buttons, the text is displayed TextBlock by clicking
Application: WPF Application consisting of a textbox on top and a listbox below Users
application = webapp.WSGIApplication( [(r'/main/profile/([a-f0-9]{40})', ProfileHandler)], debug=True) The regex in the above parameter will not
My application that is not on Play Store verify on the web If there
Application : HTA (therefore IE) This is an application that uses SendKeys to populate
Application is written in delphi 2010 and the underlying dll is a C++ dll.
Application[temp] = 8; should set the value 8 to the key temp . However,
Application names on Google Play don't need to be unique, and it's possible to
Application is running in my local system app.config file <add key=dbconn value=Data Source=(local);database=VTech;User ID=sa;Password=sa;

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.