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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:25:39+00:00 2026-06-17T21:25:39+00:00

I have the following code to draw inner shadows on my UIView drawRect: //add

  • 0

I have the following code to draw inner shadows on my UIView drawRect:

//add some inner shadow to the card box
    CGContextSaveGState(context);

    CGMutablePathRef cardPath = CGPathCreateMutable();
    CGPathAddRect(cardPath, NULL, CGRectInset(mainRect, -42, -42));
    CGPathAddPath(cardPath, NULL, mainPathRef);
    CGPathCloseSubpath(cardPath);

    // Add the visible paths as the clipping path to the context
    CGContextAddPath(context, mainPathRef);
    CGContextClip(context);

    // Now setup the shadow properties on the context
    UIColor *innerShadowColor = [UIColor colorWithWhite:133/255.f alpha:1.0];
    CGContextSetShadowWithColor(context, CGSizeMake(0.0f, 1.0f), 30.0f, [[UIColor orangeColor] CGColor]);

    // Now fill the rectangle, so the shadow gets drawn
    [innerShadowColor setFill];
    CGContextSaveGState(context);
    CGContextAddPath(context, cardPath);
    CGContextEOFillPath(context);
    CGContextRestoreGState(context);

    // Release the paths
    CGPathRelease(cardPath);

    CGContextRestoreGState(context);

    CGPathRelease(mainPathRef);

The issue is that this is really slow. Is there any way to speed this code up a bit?

  • 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-17T21:25:41+00:00Added an answer on June 17, 2026 at 9:25 pm

    If possible, I would create shadow in image editor, save it as png and then resize and tile as needed.

    Another idea is to use shouldRasterize property of CALayer. It will cache the result of drawing and use it while your view remains unchanged. In this case performance depends on how often you modify your view contents.

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

Sidebar

Related Questions

I have the following code to draw text centered vertically (and horizontally) in a
I have the following code for writing draw calls to a back buffer canvas,
I have the following code in my Rails application's routes file: MyApp::Application.routes.draw do constraints
I have the following code which does nothing but reading some values from a
I have the following code to draw a square outline with the following code.
I have the following code to draw an array of points but it only
I have the following code to draw candlestick visualization. But the visualization is not
I currently have the following code to try and allow the user to draw
I have the following code: -(void)drawRect:(CGRect)rect { // gradient background CAGradientLayer *gradient = [CAGradientLayer
I have the following code which is supposed to draw a stroked and filled

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.