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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:08:19+00:00 2026-06-03T07:08:19+00:00

i have rounded rect UIButton and want to add shadow to it, but when

  • 0

i have rounded rect UIButton and want to add shadow to it, but when i set the background image shadow is not visible, i think background overlays the shadow. without background image shadow is visible

customBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    customBtn.frame=CGRectMake(customBtn.frame.origin.x, customBtn.frame.origin.y, 30, 30);
     [customBtn setImage:[UIImage imageNamed:@"icon.png"] forState:UIControlStateNormal];
     [customBtn setBackgroundImage:[[UIImage imageNamed:@"bg.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0] forState:UIControlStateNormal];
    customBtn.layer.cornerRadius=9;

 customBtn.layer.shadowColor = [UIColor redColor].CGColor;
    customBtn.layer.shadowOpacity = 1.0;
    customBtn.layer.shadowRadius = 1;
    customBtn.layer.shadowOffset = CGSizeMake(2.0f, 2.0f);
customBtn.clipsToBounds=YES;
  • 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-03T07:08:21+00:00Added an answer on June 3, 2026 at 7:08 am

    Due to the internal structure of UIButton, your best bet is to create a stretchable background image which includes the shadow.

    UIImage *bgWithShadow = [[UIImage imageNamed: @"bg.png"] 
                                stretchableImageWithLeftCapWidth: 10 
                                                    topCapHeight: 0];
    [customBtn setBackgroundImage: bgWithShadow 
                         forState: UIControlStateNormal];
    

    This example assumes that bg.png is a 21-pixels wide image which includes a shadow. Basically, you don’t have to do anything else like accessing the button’s layer or changing its clipsToBounds property. See this question to get an idea of what a stretchable image is (with pictures!).

    Note that stretchableImageWithLeftCapWidth:topCapHeight: is being deprecated in favor of resizableImageWithCapInsets:.

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

Sidebar

Related Questions

I have an UIButton made with IB, it is set to Rounded Rect. At
I have a page that uses a background image to do rounded corners, and
I have a rounded UIImageView. When I add a shadow to it, I lose
I have nav a bar on my site but I want to put rounded
I am trying to set an image as the background of a custom UIButton.
Sorry if this belongs on a maths forum. I have an image rounded corners
I have this CSS style that does a rounded corners for div border, but
I'm using following code to add rounded corners to my UIImage, but the problem
Do I have to create (or download) images for iPhone UIButton's? I want a
- (UIImage *)roundedCornerImage:(NSInteger)cornerSize borderSize:(NSInteger)borderSize { // If the image does not have an alpha

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.