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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:34:20+00:00 2026-06-03T17:34:20+00:00

In objective C, one can set a background image to a stretched png like

  • 0

In objective C, one can set a background image to a stretched png like so:

button = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 300, 44)];
[button setTitle: @"Tap me" forState: UIControlStateNormal];
[button setBackgroundImage:[[UIImage imageNamed: @"greenButton.png"]
                                 stretchableImageWithLeftCapWidth:8.0f
                                 topCapHeight:0.0f]
                       forState:UIControlStateNormal];

Trying to transpose this over to Ruby, I keep getting exceptions though. The problem is with the two methods called on the UIImage instance: stretchableImageWithLeftCapWidth and topCapHeight.

I’ve tried the following to no avail:

greenImage = UIImage.imageNamed("greenButton.png")
greenImage.stretchableImageWithLeftCapWidth = 8.0
greenImage.topCapHeight = 0.0
@timerButton.setBackgroundImage(greenImage, forState: UIControlStateNormal)

Can anyone advise?

  • 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-03T17:34:23+00:00Added an answer on June 3, 2026 at 5:34 pm

    You have incorrectly broken that method selector up

    It is declared as

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight
    

    it should be called like this

    greenImage.stretchableImageWithLeftCapWidth(8.0, topCapHeight:0.0)
    

    You’ll most likely want to assign that to something so it might look like this

    greenImage = UIImage.imageNamed("greenButton.png")
    greenImage = greenImage.stretchableImageWithLeftCapWidth(8.0, topCapHeight:0.0)
    @timerButton.setBackgroundImage(greenImage, forState: UIControlStateNormal)
    

    Side note

    You are correct the method is marked as newly deprecated in iOS 5, but it’s also important to note that the replacement method was also introduced in iOS 5 so if you plan to support older iOS’s then you will need to continue using this.

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

Sidebar

Related Questions

Can any one tell me why Objective-C is called a run-time language
Can a Objective c interface have more than one implementation? Example I could have
Coming from a C++ background, one thing that confuses me about Objective C is
How can I draw to an image in objective-c? all I need to do
Objective-C uses a sophisticated message-passing system when one object calls a method on another
When one implements an interface (equivalent to a protocol in Objective-C) in the .Net
I am wondering how one is supposed to format Objective C code using the
I am attempting to wrap my head around one part of the Objective-C memory
I am currently learning objective-c from a book. In one example, before the class
I'm making a simple program in Objective-C. It has one class with a lot

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.