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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:53:27+00:00 2026-06-06T04:53:27+00:00

I’m trying to programmatically recreate the indented button look that can be seen on

  • 0

I’m trying to programmatically recreate the indented button look that can be seen on a UINavigationBarButton. Not the shiny two tone look or the gradient, just the perimeter shading:

enter image description here

It looks like an internal dark shadowing around the entire view perimeter, slightly darker at the top? And then an external highlighting shadow around the lower view perimeter.

I’ve played a bit with Core Graphics, and experimented with QuartzCore and shadowing with view.layer.shadowRadius and .shadowOffset, but can’t even get the lower highlighting to look right. I’m also not sure where to start to achieve both a dark shadowing with internal offset and a light shadowing with external offset.

  • 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-06T04:53:28+00:00Added an answer on June 6, 2026 at 4:53 am

    It seems as though you want a border that looks looks like a shadow. Since the shadow appears to some sort of gradient, setting a border as a gradient won’t be possible at first glance. However, it is possible to create a path that represents the border and then fill that with a gradient. Apple provides what seems to be a little known function called CGPathCreateCopyByStrokingPath. This takes a path (say, a rounded rect, for example) and creates a new path that would be the stroke of the old path given the settings you pass into the function (like line width, join/cap setting, miter limit, etc). So lets say you define a path (this isn’t exactly what Apple provides, but’s it’s similar):

    + (UIBezierPath *) bezierPathForBackButtonInRect:(CGRect)rect withRoundingRadius:(CGFloat)radius{
        UIBezierPath *path = [UIBezierPath bezierPath];
        CGPoint mPoint = CGPointMake(CGRectGetMaxX(rect) - radius, rect.origin.y);
        CGPoint ctrlPoint = mPoint;
        [path moveToPoint:mPoint];
    
        ctrlPoint.y += radius;
        mPoint.x += radius;
        mPoint.y += radius;
        if (radius > 0) [path addArcWithCenter:ctrlPoint radius:radius startAngle:M_PI + M_PI_2 endAngle:0 clockwise:YES];
    
        mPoint.y = CGRectGetMaxY(rect) - radius;
        [path addLineToPoint:mPoint];
    
        ctrlPoint = mPoint;
        mPoint.y += radius;
        mPoint.x -= radius;
        ctrlPoint.x -= radius;
        if (radius > 0) [path addArcWithCenter:ctrlPoint radius:radius startAngle:0 endAngle:M_PI_2 clockwise:YES];
    
        mPoint.x = rect.origin.x + (10.0f);
        [path addLineToPoint:mPoint];
    
        [path addLineToPoint:CGPointMake(rect.origin.x, CGRectGetMidY(rect))];
    
        mPoint.y = rect.origin.y;
        [path addLineToPoint:mPoint];
    
        [path closePath];
        return path;
    }
    

    This returns a path similar to Apple’s back button (I use this in my app). I have added this method (along with dozens more) as a category to UIBezierPath.

    Now lets add that inner shadow in a drawing routine:

    - (void) drawRect:(CGRect)rect{
        UIBezierPath *path = [UIBezierPath bezierPathForBackButtonInRect:rect withRoundingRadius:5.0f];
        //Just fill with blue color, do what you want here for the button
        [[UIColor blueColor] setFill]; 
        [path fill];
    
        [path addClip]; //Not completely necessary, but borders are actually drawn 'around' the path edge, so that half is inside your path, half is outside adding this will ensure the shadow only fills inside the path
    
        //This strokes the standard path, however you might want to might want to  inset the rect, create a new 'back button path' off the inset rect and create the inner shadow path off that.  
        //The line width of 2.0f will actually show up as 1.0f with the above clip: [path addClip];, due to the fact that borders are drawn around the edge 
        UIBezierPath *innerShadow = [UIBezierPath bezierPathWithCGPath: CGPathCreateCopyByStrokingPath(path.CGPath, NULL, 2.0f, path.lineCapStyle, path.lineJoinStyle, path.miterLimit)];
        //You need this, otherwise the center (inside your path) will also be filled with the gradient, which you don't want
        innerShadow.usesEvenOddFillRule = YES;
        [innerShadow addClip];
    
        //Now lets fill it with a vertical gradient
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGPoint start = CGPointMake(0, 0);
        CGPoint end = CGPointMake(0, CGRectGetMaxY(rect));
        CGFloat locations[2] = { 0.0f, 1.0f};
        NSArray *colors =  [NSArray arrayWithObjects:(id)[UIColor colorWithWhite:.7f alpha:.5f].CGColor, (id)[UIColor colorWithWhite:.3f alpha:.5f].CGColor, nil];
        CGGradientRef gradRef = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), (__bridge CFArrayRef)colors, locations);
        CGContextDrawLinearGradient(context, gradRef, start, end, 0);
        CGGradientRelease(gradRef);
    }
    

    Now this is just a simple example. I don’t save/restore contexts or anything, which you’ll probably want to do. There are things you might still want to do to make it better, like maybe inset the ‘shadow’ path if you want to use a normal border. You might want to use more/different colors and locations. But this should get you started.

    UPDATE

    There is another method you can use to create this effect. I wrote an algorithm to bevel arbitrary bezier paths in core graphics. This can be used to create the effect you’re looking for. This is an example of how I use it in my app:

    Bevelled Back Button

    You pass to the routine the CGContextRef, CGPathRef, size of the bevel and what colors you want it to use for the highlight/shadow.

    The code I used for this can be found here:Github – Beveling Algorithm.

    I also explain the code and my methodology here: Beveling-Shapes in Core Graphics

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.