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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:02:42+00:00 2026-05-25T17:02:42+00:00

I am trying to add a bunch of UIButton to a horizontal UIScrollView using

  • 0

I am trying to add a bunch of UIButton to a horizontal UIScrollView using the following code, however I am not seeing anything and all I see is just a white UIScrollBar. Why is this? I am pretty sure that I messed up something as before it was just working just fine.

self.category = [[NSArray alloc]initWithObjects:@"ALL", @"FOOD",@"NIGHT LIFE",@"ARTS & ENTERTAINMENT",@"SPORT", @"SHOP", @"COLLEGE & UNIVERSITY", @"TRAVEL SPOT", nil];
self.scrollView.delegate = self;
    self.scrollView.scrollEnabled = YES;
    self.scrollView.autoresizingMask = YES;

    int xOffset = 0;

    for(int index=0; index < [self.category count]; index++)
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button.titleLabel setTextAlignment:UITextAlignmentCenter];
        [button setBackgroundImage:[UIImage imageNamed:@"CategoryTab.png"] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTag:index];
        [button addTarget:self action:@selector(pressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitle:[self.category objectAtIndex:index] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont fontWithName:@"bebas" size:15.0]];
        CGSize maximumLabelSize = CGSizeMake(300,9999);
        CGSize expectedLabelSize = [[self.category objectAtIndex:index] sizeWithFont:[UIFont fontWithName:@"ArialMT" size:15.0]                     
                                      constrainedToSize:maximumLabelSize 
                                          lineBreakMode:UILineBreakModeWordWrap];
        [button setFrame: CGRectMake(xOffset, 0, expectedLabelSize.width + 30, 38)];
        [self.scrollView addSubview:button];
        xOffset += expectedLabelSize.width + 30;
        [button release];
    }
     self.scrollView.contentSize = CGSizeMake(xOffset, 38);
  • 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-25T17:02:43+00:00Added an answer on May 25, 2026 at 5:02 pm

    A few possible causes :

    • The UIButton is released once too often. It’s created autoreleased, then added to the scrollview, then released, which effectively means it will be dealloc’d when the autorelease pool ends. I’m surprised this does not crash, actually. Are you using Automatic Reference Counting?
    • is self.scrollview correctly initialized? If it’s nil, it will simply fail silently.
    • is the “bebas” font really loaded and available? Custom font loading isn’t that trivial on iOS.

    Also :

    • You’re not using the actual button font to measure the label size. (“bebas” vs “ArialMT”)
    • you probably have a leak on line 1. That NSArray would better be autoreleased ( using[NSArray arrayWithObjects:...]).
    • autoresizingMask is not a BOOL value, it’s an OR combination of flags.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to add a bunch of map markers to a map using
I'm trying to add some UnitTests to a bunch of Cocoa Legacy code. I
I'm trying to add a ViewController to my TableView cell however it is not
I'm trying add a tab to my web page that looks like this: Using
I am trying to add a bunch of controls dynamically in rows and columns
I am trying to add javascript validation to a bunch of check boxes, basically
I'm trying to add some jQuery stuff to Gmail using a GreaseMonkey script. Adding
I'm trying to add a bunch of buttons to a layout like this: for(
I'm trying to sort a bunch of products by customer ratings using a 5
I'm trying to write some code to automatically configure a bunch of scheduled tasks

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.