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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:44:46+00:00 2026-05-21T11:44:46+00:00

I’m creating a UIToolbar with nothing but a UILabel placed on it. the label

  • 0

I’m creating a UIToolbar with nothing but a UILabel placed on it. the label content is dynamic and can change and I’d like to center it on a UIToolbar.

Does anyone know the exact margin size for the left and right sides of a UIToolbar?

I’m creating a [[UIBarButtonItem alloc] initWithCustomView:myLabelContainer] and I’m trying to ensure that myLabelContainer takes up the entire toolbar space, minus the forced margins.

Right now I’ve guessed that the margins are about 12 px on each side so a UIView with a frame width of 296 should fill the entire UIToolbar?

Is this information available anywhere?

  • 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-21T11:44:47+00:00Added an answer on May 21, 2026 at 11:44 am

    I don’t think this information is available.
    But it should be pretty easy to get with some testing.

    If what you need is just a UILabel over the whole toolbar, I would suggest just to add it to the UIToolbar, which is a UIView subclass. You don’t need all the UIBarButtonItem features in your case…. just the background I presume.

    Then setting UILabel.frame (with the margins you want) + addSubview: + a UITextAlignmentCenter should do the job! Plus maybe also a autoresizingMask with UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight if you have manage device Orientation…

    EDIT 1 :

    Since there are some doubts about that proposal, I made a quick test :

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, 44)] autorelease];
    label.text = @"Hello world";
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor blackColor];
    label.backgroundColor = RGBACOLOR(255, 0, 0, .3f);
    [self.toolbar addSubview:label];
    

    Here is the result :

    enter image description here

    EDIT 2 :

    Now that I’ve launced Xcode and wrote some code, that’s easy to figure your primary question. Altering a bit the previous code :

    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
    ... same
    [self.toolbar setItems:
     [NSArray arrayWithObject:
      [[[UIBarButtonItem alloc] initWithCustomView:label] autorelease]]];
    

    brings that :

    toolbar2

    So as you guessed, there is a left margin of 12px, but Custom views doesn’t look like to be resized to fit, therefore, no right margin in that case… unless you resize your view accordingly.

    EDIT 3 :

    Unless your UILabel needs a background, here is what I would probably do (That’s what UIBarButtonSystemItemFlexibleSpace are for after all…) :

    UILabel *label = [[[UILabel alloc] init] autorelease];
    label.text = @"Hello world";
    ... same
    [label sizeToFit];
    [self.toolbar setItems:
     [NSArray arrayWithObjects:
      [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                     target:nil action:nil] autorelease],
      [[[UIBarButtonItem alloc] initWithCustomView:label] autorelease],
      [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
                                                     target:nil action:nil] autorelease],
      nil]];
    

    The result :

    enter image description here

    EDIT 4 :

    As a side not, after working more on a UIToolbar, 12px is the default space added before a button. And I’ve just discovered a fun one, spacers are working with negative values!. I.E. if you want a 2px space between two buttons, just add a -10px UIBarButtonSystemItemFixedSpace… Handy!

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

Sidebar

Related Questions

No related questions found

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.