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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:18:12+00:00 2026-06-13T04:18:12+00:00

I have the following image representing my button: I want to use that image

  • 0

I have the following image representing my button:

enter image description here

I want to use that image to create a button that uses that as the background, but that is much wider than the image I supplied.

Here are the two methods that I have tried:

  UIButton *emailSupportButton = [[UIButton alloc] initWithFrame:CGRectMake(25, 315, 200, 60)];
  [emailSupportButton setTitle:@"Email Support" forState:UIControlStateNormal];
  [emailSupportButton setImage:[UIImage imageNamed:@"toolbar-button"] forState:UIControlStateNormal];

This method results in the button image not being stretched and displaying exactly how the .png would display normally.

The other method I have tried is setting the background image, like so…

  UIButton *emailSupportButton = [[UIButton alloc] initWithFrame:CGRectMake(25, 315, 200, 60)];
  [emailSupportButton setTitle:@"Email Support" forState:UIControlStateNormal];
  [emailSupportButton setBackgroundImage:[UIImage imageNamed:@"toolbar-button"] forState:UIControlStateNormal];

This method stretches the image in a really ugly fashion instead of achieving the desired effect, causing the button to be almost elliptical with a really ugly border.

Is the problem that I am not using the right method of creating a custom button, or that my image is not suitable for the task I am trying to accomplish? Is my image supposed to be rectangular and not include the button’s border, letting UIButton take care of the border/rounding for me? Is my image supposed to already be the size of the button (this seems a bit limiting)?

  • 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-13T04:18:13+00:00Added an answer on June 13, 2026 at 4:18 am

    The second method you listed (code-wise) is what you want. What you are missing is the stretchable image. Try this:

    UIButton *emailSupportButton = [[UIButton alloc] initWithFrame:CGRectMake(25, 315, 200, 60)];
    [emailSupportButton setTitle:@"Email Support" forState:UIControlStateNormal];
    UIImage *backgroundImage = [UIImage imageNamed:@"toolbar-button"];
    CGSize size = backgroundImage.size;
    backgroundImage = [backgroundImage stretchableImageWithLeftCapWidth:size.width/2.0 topCapWidth:size.height/2.0];
    [emailSupportButton setBackgroundImage:backgroundImage forState:UIControlStateNormal];
    

    If you are deploying on iOS 5 and greater only, then you will want to use the new -[UIImage resizableImageWithCapInsets:(UIEdgeInsets)capInsets]; iOS 6 also adds -[UIImage resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode];

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

Sidebar

Related Questions

I have following Image as src in ImageView. I use this as background image.
I have the following image in a CMS that I want to hide, I
I have the following image element that it's src does not exists. I want
I have the following: Background image (bi) Image1 (i1) Image3 (i2) I want to
I want to have a JPanel which uses an image as a background, with
I have the following image button on the GridView and I want to call
I have a variable representing a bmp image with the following structure: image=[line1, line2,
We suppose that we have the following image (is a single file with 4
I have the following code: Image tmpimg = null; HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); HttpWebResponse
i have following coding to resize image and than save it my virtual folder

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.