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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:02:29+00:00 2026-06-03T23:02:29+00:00

Difficult to explain this question. I am attempting to create a set of UIButtons

  • 0

Difficult to explain this question. I am attempting to create a set of UIButtons on screen which is based on the number of entries in an NSArray. I have created an NSArray containing a number of images, like so:

socialArray = [[NSArray alloc] initWithObjects:
                   [UIImage imageNamed:@"FacebookButton.png"],
                   [UIImage imageNamed:@"WebsiteSocialButton.png"],
                   [UIImage imageNamed:@"TumblrButton.png"],
                   [UIImage imageNamed:@"TwitterButton.png"],
                   [UIImage imageNamed:@"InstagramButton.png"],
                   [UIImage imageNamed:@"VimeoButton.png"],
                   [UIImage imageNamed:@"GooglePlusButton.png"],
                   [UIImage imageNamed:@"YouTubeButton.png"],
                   [UIImage imageNamed:@"PinterestButton.png"],
                  nil];

and am creating the number of items in the view based on that, like so:

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    return [socialArray count];
}

I am then programatically creating the button and setting its image, like so:

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{ 
    UIButton *button = (UIButton *)view;
    if (button == nil)
    {
        //no button available to recycle, so create new one
        UIImage *image = [UIImage imageNamed:@"page.png"];
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setBackgroundImage:image forState:UIControlStateNormal];
        button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
        [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
    }

    //set button label
    [button setTitle:[socialArray objectAtIndex:0] forState:UIControlStateNormal];

    return button;
}

What I really want to do is set the image of the button based on the specified image in an array. So, the first button gets the PNG file specified at index 0, second button gets image at index 1 and so on.

Any advice on how I can do that?

  • 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-03T23:02:30+00:00Added an answer on June 3, 2026 at 11:02 pm
    UIImage *image = [socialArray objectAtIndex:index];
    

    (You have to do this outside of the if statement, otherwise the image wouldn’t be set for buttons that are reused.)

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

Sidebar

Related Questions

It is very difficult for me to explain this particular problem/question so please bear
This is such a difficult question to explain online but I shall try my
Difficult to explain this Question, but im currently passing variables in a php page
The question is a bit difficult to explain, but I will try. I have
Apologies for the vague title, but this is quite a difficult problem to explain
I have a problem that is kind of difficult to explain. What I would
My question is not easy to explain using words, fortunately it's not too difficult
This is a hard one to explain but here goes. I have 2 arrays,
This may be difficult to explain. I want to specify two indexes, and then
This situation is pretty difficult to explain, but I'll do my best. For school,

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.