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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:52:58+00:00 2026-05-31T16:52:58+00:00

I have a problem with UIButton image if I set its imageView contentMode to

  • 0

I have a problem with UIButton image if I set its imageView contentMode to UIViewContentModeScaleAspectFill.

UIButton *imageButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 200, 100)];
imageButton.imageView.contentMode = UIViewContentModeScaleAspectFill;
[imageButton setImage:[UIImage imageNamed:@"myImage.jpg"] forState:UIControlStateNormal];
[imageButton addTarget:self action:@selector(doSmth:) forControlEvents:UIControlEventTouchUpInside];

The image inside button is properly scaled to fill the whole button area.

After a click/touch on button the image gets resized (flickers) like if it’s contentMode is set to UIViewContentModeScaleAspectFit.

Does anyone know how to remove this flickering when click/touch occurs?

Thanks!

  • 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-31T16:53:00+00:00Added an answer on May 31, 2026 at 4:53 pm

    Why are you setting content mode of the button’s imageView? The image, you set for specified state, is always filling the size of the button. So you have to set button’s frame size to the size of the image and not to set imageView contentMode

    The flickering could be the higlighting of the button. If you want to set custom image for highlighting, use this code:

    [imageButton setImage:buttonHightlightImage forState:UIControlStateHightlighted]
    
    • 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: self.shareButton=[[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 35, 35)]; [shareButton setBackgroundColor:[UIColor blueColor]];
I have UIButton that I set the background image for three states, normal, highlighted,
I have a UIButton, and I'm adding an image to it using this code:
I have really weird problem with colors in interface builder. I set a color
I have a UIButton which has images set for both Normal and Selected State.
I have this problem of my app crashing (only when press a certain UIButton)
I have a problem with my image animation. here is the .h @interface Flash_ViewController
Recently I've encountered a problem. I have a UIButton and 2 images for it.
I have a bit of an odd problem with an image I'm using in
I have an image displayed using CGRect (code below). the problem is that it's

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.