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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:25:44+00:00 2026-05-25T13:25:44+00:00

Ive added buttons to my view programmatically and i want to later on change

  • 0

Ive added buttons to my view programmatically and i want to later on change their background color. The buttons are of type custom. The following code has no effect.

    for(UIView *v in [self.view subviews]){
        if ([v isKindOfClass:[UIButton class]]){ 
            //NSLog(@"View : %@", v);
            [v setBackgroundColor:[UIColor redColor]];
        } 
    }

Could some one please assist?

  • 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-25T13:25:45+00:00Added an answer on May 25, 2026 at 1:25 pm

    To paraphrase – you cannot change the color of UIButton (with UIButtonTypeRoundedRect). When you try changing it’s background color you’re rather changing the color of the rect the button is drawn on (which is usually clear). So there are two ways to go. Either you subclass UIButton and overwrite its -drawRect: method or you create images for the different button states (which is perfectly fine to do).

    If you are using IB to set background images you will notice that IB doesn’t support setting images for all the states the button can have, so I recommend setting the images in code like so –

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"normal.png"] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:@"disabled.png"] forState:UIControlStateDisabled];
    [button setBackgroundImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateSelected];
    [button setBackgroundImage:[UIImage imageNamed:@"higligted.png"] forState:UIControlStateHighlighted];
    [button setBackgroundImage:[UIImage imageNamed:@"highlighted+selected.png"] forState:(UIControlStateHighlighted | UIControlStateSelected)];
    

    The last line shows how to set an image for the selected & highlighted state (that’s the one IB can’t set). You don’t need the selected images (line 4 & 6) if you’re button dosn’t need a selected state.

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

Sidebar

Related Questions

I've added 2 image buttons in my master page. Their purpose is to change
I've added some buttons to an UIView (via addSubview) programmatically. However, they appear as
I've added the following code to my masterpage (Page_Load) so once a user logs
I'm having a problem with the following code. I want to use one UIImageView
I have a view that I created using default buttons and background in Interface
I want each of my views to have their own toolbar buttons, particular to
I've created a series of buttons and added them to the view, I was
I have a UIButton which I've added in IB, however the view behind this
I've added the following image to help illustrate the problem better: Hi, I'm looking
i am developing a simple view based application which contains two buttons and a

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.