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

The Archive Base Latest Questions

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

In my iPad app, I want a second view to appear within the main

  • 0

In my iPad app, I want a second view to appear within the main when the user clicks a button. The new view will be smaller than the first, and darken the background when it is displayed. I want the top two corners of the new view to appear rounded, but using cornerRadius sets all of them rounded. How can I make just two corners rounded?

  • 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-19T15:27:14+00:00Added an answer on May 19, 2026 at 3:27 pm

    You have to do this in drawRect:. I actually modified the classic addRoundedRectToPath: so that it takes a bitmap and rounds the corners you request:

    static void addRoundedRectToPath(CGContextRef context, CGRect rect, float radius, UIImageRoundedCorner cornerMask)
    {
        CGContextMoveToPoint(context, rect.origin.x, rect.origin.y + radius);
        CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height - radius);
        if (cornerMask & UIImageRoundedCornerTopLeft) {
            CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + rect.size.height - radius, 
                            radius, M_PI, M_PI / 2, 1);
        }
        else {
            CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + rect.size.height);
            CGContextAddLineToPoint(context, rect.origin.x + radius, rect.origin.y + rect.size.height);
        }
    
        CGContextAddLineToPoint(context, rect.origin.x + rect.size.width - radius, 
                              rect.origin.y + rect.size.height);
    
        if (cornerMask & UIImageRoundedCornerTopRight) {
            CGContextAddArc(context, rect.origin.x + rect.size.width - radius, 
                            rect.origin.y + rect.size.height - radius, radius, M_PI / 2, 0.0f, 1);
        }
        else {
            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 + rect.size.height - radius);
        }
    
        CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y + radius);
    
        if (cornerMask & UIImageRoundedCornerBottomRight) {
            CGContextAddArc(context, rect.origin.x + rect.size.width - radius, rect.origin.y + radius, 
                            radius, 0.0f, -M_PI / 2, 1);
        }
        else {
            CGContextAddLineToPoint(context, rect.origin.x + rect.size.width, rect.origin.y);
            CGContextAddLineToPoint(context, rect.origin.x + rect.size.width - radius, rect.origin.y);
        }
    
        CGContextAddLineToPoint(context, rect.origin.x + radius, rect.origin.y);
    
        if (cornerMask & UIImageRoundedCornerBottomLeft) {
            CGContextAddArc(context, rect.origin.x + radius, rect.origin.y + radius, radius, 
                            -M_PI / 2, M_PI, 1);
        }
        else {
            CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y);
            CGContextAddLineToPoint(context, rect.origin.x, rect.origin.y + radius);
        }
    
        CGContextClosePath(context);
    }
    

    This takes a bitmask (I called it UIImageRoundedCorner because I was doing this for images, but you can call it whatever) and then builds up a path based on the corners you want rounded. Then you apply that path to the view in drawRect:

    CGContextBeginPath(context);
    addRoundedRectToPath(context, rect, radius, yourMask);
    CGContextClosePath(context);
    CGContextClip(context);
    

    As I said, I was doing this for UIImages, so my code isn’t exactly set up for use in drawRect:, but it should be pretty easy to adapt it. You’re basically just building up a path and then clipping the context to it.

    Edit: To explain the bitmask part, it’s just an enum:

    typedef enum {
        UIImageRoundedCornerTopLeft = 1,
        UIImageRoundedCornerTopRight = 1 << 1,
        UIImageRoundedCornerBottomRight = 1 << 2,
        UIImageRoundedCornerBottomLeft = 1 << 3
    } UIImageRoundedCorner;
    

    In this way you can OR things together to form a bitmask that identifies corners, since each member of the enum represents a different power of two in the bitmask.

    Much Later Edit:
    I’ve discovered an easier way to do this using UIBezierPath‘s bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:. Just use the bezier path object’s CGPath in your context.

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

Sidebar

Related Questions

I want to create an iPad app which will initially show a Table View
I want to created a view in UITabBarController as the iPad App shown (see
I want to provide a user-input field in my iPad app, where the user
In an iPad app, wherever a user is touching the screen I want to
I am creating an iPad app and want to update the user with the
I have an iPad app with split view controller. I want to programmaticaly create
I'm making the app-book for ipad like app-magazine. Now I'm using ScrollView and want
i want to record my app in ipad is there any esay way to
I am building an iPad app where all views should autorotate. One view is
I have a button on a view, I want to add another button next

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.