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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:56:33+00:00 2026-05-20T16:56:33+00:00

Historic question. Note that 15 years later, .imagePadding is the space between the image

  • 0

Historic question. Note that 15 years later, .imagePadding is the space between the image and label.

enter image description here


Original question:

I would like to place an icon left of the two lines of text such that there’s about 2-3 pixels of space between the image and the start of text. The control itself is Center aligned horizontally (set through Interface Builder)

The button would resemble something like this:

|                  |
|[Image] Add To    |
|        Favorites |

I’m trying to configure this with contentEdgeInset, imageEdgeInsets and titleEdgeInsets to no avail. I understand that a negative value expands the edge while a positive value shrinks it to move it closer to the center.

I tried:

[button setTitleEdgeInsets:UIEdgeInsetsMake(0, -image.size.width, 0, 0)];
[button setImageEdgeInsets:UIEdgeInsetsMake(0, button.titleLabel.bounds.size.width, 0, 0)];

but this doesn’t display it correctly. I’ve been tweaking the values but going from say -5 to -10 on the left inset value doesn’t appear to move it in expected manner. -10 will scoot the text all the way to the left so I expected -5 to scoot it half way from the left side but it doesn’t.

What’s the logic behind insets? I’m not familiar with image placements and related terminology.

I used this SO question as a reference but something about my values isn’t right.
UIButton: how to center an image and a text using imageEdgeInsets and titleEdgeInsets?

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

    I agree the documentation on imageEdgeInsets and titleEdgeInsets should be better, but I figured out how to get the correct positioning without resorting to trial and error.

    The general idea is here at this question, but that was if you wanted both text and image centered. We don’t want the image and text to be centered individually, we want the image and the text to be centered together as a single entity. This is in fact what UIButton already does so we simply need to adjust the spacing.

    CGFloat spacing = 10; // the amount of spacing to appear between image and title
    tabBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, spacing);
    tabBtn.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
    

    I also turned this into a category for UIButton so it will be easy to use:

    UIButton+Position.h

    @interface UIButton(ImageTitleCentering)
    
    -(void) centerButtonAndImageWithSpacing:(CGFloat)spacing;
    
    @end
    

    UIButton+Position.m

    @implementation UIButton(ImageTitleCentering)
    
    -(void) centerButtonAndImageWithSpacing:(CGFloat)spacing {
        self.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, spacing);
        self.titleEdgeInsets = UIEdgeInsetsMake(0, spacing, 0, 0);
    }
    
    @end
    

    So now all I have to do is:

    [button centerButtonAndImageWithSpacing:10];
    

    And I get what I need every time. No more messing with the edge insets manually.

    EDIT: Swapping Image and Text

    In response to @Javal in comments

    Using this same mechanism, we can swap the image and the text. To accomplish the swap, simply use a negative spacing but also include the width of the text and the image. This will require frames to be known and layout performed already.

    [self.view layoutIfNeeded];
    CGFloat flippedSpacing = -(desiredSpacing + button.currentImage.size.width + button.titleLabel.frame.size.width);
    [button centerButtonAndImageWithSpacing:flippedSpacing];
    

    Of course you will probably want to make a nice method for this, potentially adding a second category method, this is left as an exercise to the reader.

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

Sidebar

Related Questions

Please note that this question is from 2008 and now is of only historic
Is there a historic reason that periods are used instead of any other separator
I have a data.frame that contains historic data by day for several months. I
I've currently got a string value in one table, which I would like to
This question is about a whole class of similar problems, but I'll ask it
There was a similar question discussed around collaboration tools but one point wasn't fully
Currently I have a structure like this: A | +--B | +--C It's mapped
I'm trying to find duplicate keys so that they can be addressed and made
Most of the applications I've seen that use TCP, do roughly the following to
<Historic> -----<ReturnData Year=2010> ----- -----<ReturnHistory> ----- -----<Return StoreDate=2010-07-31 Type=1> ----- -----<EndDate>2010-01-31</EndDate> ----- -----<ReturnDetail TimePeriod=1>

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.