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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:59:07+00:00 2026-05-20T05:59:07+00:00

Behold: //UIImageView* stretchTest = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@image.png]]; //[self addSubview:stretchTest]; UIButton *stretchTest = [UIButton

  • 0

Behold:

//UIImageView* stretchTest = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image.png"]];
//[self addSubview:stretchTest];


UIButton *stretchTest = [UIButton buttonWithType:UIButtonTypeCustom];
[stretchTest setFrame:CGRectMake(0, 0, 400, 100)];
[stretchTest setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal];
[self addSubview:stretchTest];

stretchTest.contentStretch = CGRectMake(0.5, 0.5, 0, 0);
stretchTest.contentMode = UIViewContentModeScaleToFill;

CGRect frame = stretchTest.frame;
frame.size.height = 300;
stretchTest.frame = frame;

Using the UIImageView (commented out above), the image stretches appropriately – rounded corners maintain the correct radius, because only the center pixel of the image gets stretched.

Using the UIButton, the image gets stretched incorrectly. The corner radii are not maintained and it gets ugly.

Both UIImageView and UIButton are subclasses of UIView. Why does the button resize differently than the imageView?

  • 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-05-20T05:59:08+00:00Added an answer on May 20, 2026 at 5:59 am

    You’re making assumptions about the way UIButton works. It’s not implemented the same way as UIImageView. UIImageView is just a view, with no subviews, and its contents is the image. UIButton is different, and the way it works is a private implementation detail.

    If you’re trying to stretch an image appropriately on a button, you should use -[UIImage stretchableImageWithLeftCapWidth:topCapHeight:] to get a UIImage that knows how it should be stretched. If you want to stretch just the middle pixel, you can use something like

    UIImage *image = [UIImage imageNamed:@"image.png"];
    image = [image stretchableImageWithLeftCapWidth:floorf(image.size.width/2) topCapHeight:floorf(image.size.height/2)];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Behold the code: using (var client = new WebClient()) { using (var stream =
Behold the code: using (var client = new WebClient()) { try { var bytesReceived
Behold the C# code: IEnumerable<int> innerMethod(int parameter) { foreach(var i in Enumerable.Range(0, parameter)) {
Behold the following XAML: <Grid> <HyperlinkButton x:Name=Link Background=Green> <Grid Background=Red> <Grid.ColumnDefinitions> <ColumnDefinition Width=Auto />
this seems like a really simple Question...but behold :) Geek name:string Laser geek_id:integer, power:integer
  I understand that elements can have multiple classes: .rfrsh-btn { background-image:url(../../upload/rfrsh_nb_grey.png); ... }
Currently I'm running several websites that have several (branded) duplicates each, in the same
Not many are aware of this feature, but Python's functions (and methods) can have
I didn't imagine that I would encounter radically new syntax in Java anymore at
How do I make Apple's Cocoa GUI controls not automatically flip lines that contain

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.